Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] JsonUtils not support serialize java.time.LocalDate #4161

Closed
2 tasks done
mxsm opened this issue Jun 28, 2023 · 0 comments · Fixed by #4162
Closed
2 tasks done

[Bug] JsonUtils not support serialize java.time.LocalDate #4161

mxsm opened this issue Jun 28, 2023 · 0 comments · Fixed by #4162
Labels
bug Something isn't working
Milestone

Comments

@mxsm
Copy link
Member

mxsm commented Jun 28, 2023

Search before asking

  • I had searched in the issues and found no similar issues.

Environment

Windows

EventMesh version

master

What happened

final Map<String, Object> content = new HashMap<>();
content.put("content", "testAsyncMessage");
 content.put("content", LocalDate.now());

JsonUtils.toJSONString(content)

throw exception

How to reproduce

final Map<String, Object> content = new HashMap<>();
content.put("content", "testAsyncMessage");
 content.put("content", LocalDate.now());

JsonUtils.toJSONString(content)

Debug logs

Exception in thread "main" org.apache.eventmesh.common.exception.JsonException: serialize to json error
	at org.apache.eventmesh.common.utils.JsonUtils.toJSONString(JsonUtils.java:66)
	at org.apache.eventmesh.grpc.GrpcAbstractDemo.buildEventMeshMessage(GrpcAbstractDemo.java:71)
	at org.apache.eventmesh.grpc.pub.eventmeshmessage.AsyncPublishInstance.main(AsyncPublishInstance.java:49)
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.LocalDate` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: java.util.HashMap["content"])
	at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77)
	at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1300)
	at com.fasterxml.jackson.databind.ser.impl.UnsupportedTypeSerializer.serialize(UnsupportedTypeSerializer.java:35)
	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeOptionalFields(MapSerializer.java:869)
	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeWithoutTypeInfo(MapSerializer.java:760)
	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:720)
	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:35)
	at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
	at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
	at com.fasterxml.jackson.databind.ObjectMapper._writeValueAndClose(ObjectMapper.java:4569)
	at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3822)
	at org.apache.eventmesh.common.utils.JsonUtils.toJSONString(JsonUtils.java:64)
	... 2 more

Are you willing to submit PR?

  • Yes I am willing to submit a PR!
@mxsm mxsm added the bug Something isn't working label Jun 28, 2023
mxsm added a commit to mxsm/incubator-eventmesh that referenced this issue Jun 28, 2023
@xwm1992 xwm1992 added this to the 1.9.0 milestone Jun 29, 2023
xwm1992 pushed a commit that referenced this issue Jun 29, 2023
…4162)

* [ISSUE #4161]Fix JsonUtils not support serialize java.time.LocalDate

* fix codestyle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants