In GHRequest it is documented that it’s possible to deserialize a JSON to GHRequest with Jackson. I also saw that there is an GHResponseDeserializer.java. Can you explain why a GHRequestDeserializer is missing?
I would like to map a JSON request like this (probably wrong syntax) to a valid GHRequest object
This is done from Jackson automatically, there is no need for a GHRequestDeserializer.
There are no tests necessary as it is also implicitly tested whenever a POST request is send to a resource. I think we only have GHPointDeserializer that helps during a request deserialization to use the reverse array order.
(In master we additionally need to help jackson via a CustomModelAreasDeserializer to stay backward compatible)
It’s probably my lack of experience with Jackson but trying this:
GHRequest request = new GHRequest(new GHPoint(53.33918, -6.22016), new GHPoint(53.33914, -6.21668));
ObjectMapper mapper = new ObjectMapper();
String serializedGHRequest = mapper.writeValueAsString(request);
System.out.println(serializedGHRequest);
GHRequest deserializedGHRequest = mapper.readValue(serializedGHRequest, GHRequest.class);
Gives me an
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "valid" (class com.graphhopper.util.shapes.GHPoint), not marked as ignorable (2 known properties: "lon", "lat"])
If you write the object to string you need to register the serializers. If you want to read the object from the string you need to register the deserializers (you can read about it in some jackson docs). Have a look into our class com.graphhopper.jackson.Jackson on the serializers and deserializers we use.
You’ll notice that the points field will be missing without the proper deserializer (I think). Please note that our (de)serializer expects a different format ala points:[[lng,lat], ...]