Marshall @Id to JSON while retaining Java 8 time formatting -
i'm trying map object json. works fine, want expose @id
in json. i've found this answer on how that, in order use solution, have extend repositoryrestmvcconfiguration
. when extend this, java 8 time formatting breaking. json follows:
{"name":"erik",birthdate:"2015-01-01"}
the birthdate field java 8 localdate. now, try expose @id
, extending repositoryrestmvcconfiguration
, setting configuration.exposeidsfor(myclass.class);
. have id exposed, but, result of extending repositoryrestmvcconfiguration
, localdate
serialized as:
"birthdate":{"year":2015,"month":"august","chronology":{"id":"iso","calendartype":"iso8601"},"dayofmonth":15,"dayofweek":"saturday","era":"ce","dayofyear":227,"leapyear":false,"monthvalue":8}
so, question is: how can expose id of class while retaining format of localdate
?
it sounds you're hitting problem described in this spring boot issue. in short, problem presence of repositoryrestmvcconfiguration
subclass causing spring mvc's default json converter used, rather 1 you've configured. described in issue, can work around problem declaring following bean in application's configuration:
@bean public httpmessageconverters httpmessageconverters( final jackson2objectmapperbuilder builder, list<httpmessageconverter<?>> converters) { return new httpmessageconverters(converters) { @override protected list<httpmessageconverter<?>> postprocessconverters( list<httpmessageconverter<?>> converters) { (httpmessageconverter<?> converter : converters) { if (converter instanceof mappingjackson2httpmessageconverter) { builder.configure(((mappingjackson2httpmessageconverter) converter) .getobjectmapper()); } } return converters; } }; }
Comments
Post a Comment