Skip to content

Commit

Permalink
Add JavaTimeModule to ObjectSerializer
Browse files Browse the repository at this point in the history
Signed-off-by: Matheus Cruz <[email protected]>
  • Loading branch information
mcruzdev committed Jul 2, 2024
1 parent a0ee8d1 commit 0c1886f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.mockito.Mockito;
import reactor.core.publisher.Mono;

import java.time.ZonedDateTime;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -467,6 +469,8 @@ static class MyData {

private MyData myData;

private ZonedDateTime date;


public String getPropertyB() {
return propertyB;
Expand Down Expand Up @@ -499,6 +503,14 @@ public MyData getMyData() {
public void setMyData(MyData myData) {
this.myData = myData;
}

public ZonedDateTime getDate() {
return date;
}

public void setDate(ZonedDateTime date) {
this.date = date;
}
}

}
5 changes: 5 additions & 0 deletions sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@
<artifactId>grpc-inprocess</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.17.1</version>
</dependency>
</dependencies>

<build>
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/main/java/io/dapr/client/ObjectSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.google.protobuf.MessageLite;
import io.dapr.client.domain.CloudEvent;
import io.dapr.utils.TypeRef;
Expand All @@ -35,6 +36,7 @@ public class ObjectSerializer {
*/
protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModule(new JavaTimeModule())
.setSerializationInclusion(JsonInclude.Include.NON_NULL);

/**
Expand Down

0 comments on commit 0c1886f

Please sign in to comment.