ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
GHResponse response = hopper.route(request); // -> a correct response
String serializedResponse = objectMapper.writeValueAsString(response); // -> this looks fine
GHResponse deserializedResponse = objectMapper.readValue(serializedResponse, GHResponse.class); // -> error
However, I get an
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of "com.graphhopper.util.InstructionList" (no Creators, like default construct, exist): no default no-arguments constructor found
error. Is this a bug or can you point me to a workaround?
thanks for your response! I was able to get the client-hc part working as expected
So I can know serialize a GHRequest into a String (GraphHopperWeb#requestToJson) and deserialize a String into a GHResponse (part of GraphHopperWeb#route).
To make the full circle can you please tell me where in the repo (probably at server side) I find the code which
deserialize the incoming String into a GHRequest object
(performs the routing, this part works for me)
serializes the resulting GHResponse into a String
(feel free to replace String with byte[] or whatever you’re using in your implementation)
Jackson is called from jersey/dropwizard. There is no explicit server-side code in GraphHopper that does these conversions, only the (de)serializers that you found.
Yeah I just found how ResponsePathSerializer.jsonObject(...) is called in RouteResource.java which helped me to understand how you use the (de)serializers to convert GHResponse to JSON