0

I have a class at server :

Class A{
int x;
int y;
// getters and setters
}

in old client

Class A{
int x;
}

in new client

Class A{
int x;
int y;
}

now i can't change the old client code and the client gives org.codehaus.jackson.map.exc.UnrecognizedPropertyException. i can change the server or new client code.

How can i make this work with jackson serializer?

Sachin Sharma
  • 1,446
  • 4
  • 18
  • 37
  • Inheritance may work – T. Claverie May 20 '16 at 09:47
  • meaning i create a new api (wrapper) with new response. yes i could do that. i was hoping for some solution where i don't have to make new api (essentially duplicate). Maybe some clean solution that jackson provides or some small hack. – Sachin Sharma May 20 '16 at 09:57

1 Answers1

1

Different format:

You can use Views on the server to decide during runtime which properties to include. The new client could then request the same content as old client, but with a different parameter/header or via different API path that simply uses a new view with new properties.

Same format:

If the old client doesn't support the new format, you cannot simply force it to support it without modifying the client. In fact, if you could do something like this, it would be quite dangerous, as it would imply existing applications could not rely on their format restrictions.

However, if you can modify old client, here's something you can do:

  1. Add @JsonIgnoreProperties(ignoreUnknown = true) to the POJO in old client
  2. If you can't modify POJO, but can access ObjectMapper: objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  3. If you can access ObjectMapper, but don't want to affect all other POJOs too, you can mix-in the annotation just for that one POJO
Community
  • 1
  • 1
Anton Koscejev
  • 4,603
  • 1
  • 21
  • 26
  • thanks for valuable info but no can't change either old client or object mapper config. i think i will just create a new api (wrapper) and a new response object (extending the old one). :) – Sachin Sharma May 24 '16 at 05:55
  • Changing format is basically creating a new version of API. It's normal for a server to support multiple versions of API. You can check out this question for how others are handling the versioning: http://stackoverflow.com/questions/389169/best-practices-for-api-versioning – Anton Koscejev May 24 '16 at 14:40