Reputation: 21
From past few days I am struggling for an answer on this issue. I have searched each and every topic here in Stack Overflow and Google as well. Did everything what has been advised and suggested. But nothing worked.
It is a common issue but with various different reasons or root causes.
So posting here it again with my part of the problem.
org.codehaus.jackson.map.JsonMappingException: Can not instantiate value of type [simple type, class org.joda.time.LocalDateTime] from JSON String; no single-String constructor/factory method
The actual exception:
2017-06-29 05:33:06,427 | | WARN [RequestCycleExtra] (sid:) Handling the following exception: org.jboss.resteasy.spi.ReaderException: org.codehaus.jackson.map.JsonMappingException: Can not instantiate value of type [simple type, class org.joda.time.LocalDateTime] from JSON String; no single-String constructor/factory method (through reference chain: org.comp.app.rest.OrderDTO["infoMessages"]->org.comp.app.rest.InfoMessageDTO["timestamp"]) at org.jboss.resteasy.client.core.BaseClientResponse.readFrom(BaseClientResponse.java:469) [resteasy-jaxrs-2.3.3.Final.jar:] at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:377) [resteasy-jaxrs-2.3.3.Final.jar:] at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:350) [resteasy-jaxrs-2.3.3.Final.jar:] at org.jboss.resteasy.client.core.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:62) [resteasy-jaxrs-2.3.3.Final.jar:] at org.jboss.resteasy.client.core.ClientInvoker.invoke(ClientInvoker.java:120) [resteasy-jaxrs-2.3.3.Final.jar:] at org.jboss.resteasy.client.core.ClientProxy.invoke(ClientProxy.java:88) [resteasy-jaxrs-2.3.3.Final.jar:]
infoMessages is the List of the InfoMessage Entity having timestamp as one of the property InfoMessageDTO is the DTO for InfoMessage having the same properities as the DTO and has also timestamp as one of the property.
InfoMessage is filled by Hibernate mappings in the Order Entity. InfoMessage Entity is related to Order (onetomany order->infomessage).
The above operation involves calling a Rest service getOrders from app (say app-x) to another app (say app-y). the service call involves pulling out requested order data (including the related entities) from the app-x database and display it on app-y (web app).
To find the RC, I put the Hibernate trace as well. Data is coming fine and getting filled and even the JSON is prepared and responded. But could not trace the actual location of the issue as this exception is thrown between the server (from app-x) response to client (app-y) parsing. But am not 100% sure.
I even tried to annotate the @JsonSerialize and @JsonDeserialize as advised in this link for the timestamp properties in Entity and DTO as well as per many different posts here in Stack Overflow. But nothing worked!
Code with annotation of timestamp:
@JsonSerialize(using = LocalDateTimeSerializer.class)
public LocalDateTime getTimestamp() {
LOG.info("InfoMesage.getTimestamp(" + timestamp + ")");
return timestamp;
}
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
public void setTimestamp(LocalDateTime timestamp) {
LOG.info("InfoMesage.setTimestamp(" + timestamp + ")");
this.timestamp = timestamp;
}
The LocalDateTimeSerailizer/Deserializer are the customized classes extending JsonSerializer/Deserializer of jackson-mapper-asl library.
Could anyone please help guide me to resolve this issue?
Imp Note: The above two applications are Apache Wicket based. JDK 1.7, JBoss 7
thanks
Upvotes: 1
Views: 3679
Reputation: 736
I got the same error . Issue was that i was sending "creaateTimestamp" : "1529949681949" when i tried "creaateTimestamp" : 1529949681949 it worked.
Also i had added this dependency in my pom com.fasterxml.jackson.datatype jackson-datatype-joda 2.6.3
Upvotes: 1