pingidentity / scim2

The UnboundID SCIM 2.0 SDK for Java
184 stars 75 forks source link

Serialize Calendar object into a ISO8601 String timestamp #185

Closed eddyclhung closed 1 year ago

eddyclhung commented 1 year ago

Does anyone know when using the Meta object, how do we properly convert fields in Calendar type into a timestamp String in ISO8601 format while serializing into a JSON object? Thanks.

https://github.com/pingidentity/scim2/blob/a2edbb693bb2f65c1a30dc12f155e399a7117c1d/scim2-sdk-common/src/main/java/com/unboundid/scim2/common/types/Meta.java#L38

eddyclhung commented 1 year ago

I think I just found the solution. We just need to register the module. For JsonMapper, we need to use addModules instead.

SimpleModule dateTimeModule = new SimpleModule();
dateTimeModule.addSerializer(Calendar.class, new CalendarSerializer());
dateTimeModule.addDeserializer(Calendar.class, new CalendarDeserializer());
dateTimeModule.addSerializer(Date.class, new DateSerializer());
dateTimeModule.addDeserializer(Date.class, new DateDeserializer());

final JsonMapper jsonMapper =
             JsonMapper.builder()
                       .addModules(dateTimeModule)
...

https://github.com/pingidentity/scim2/blob/799c6816425bc0c43c9a7a2de1f200ed368936f2/scim2-sdk-common/src/main/java/com/unboundid/scim2/common/utils/MapperFactory.java#L148:L153

kqarryzada commented 1 year ago

Hi Eddy. Were you able to register the module successfully? Please let us know (with some additional details) if you think there is a bug.

eddyclhung commented 1 year ago

Hi Eddy. Were you able to register the module successfully? Please let us know (with some additional details) if you think there is a bug.

I was able to implement this feature by registering the module. Thanks, @kqarryzada.