Skip to content
Advertisement

java model mock response json

I am creating a Rest service which calls an external service. I have this problem: the external service I call responds in two ways depending on the case of Success or Failed. This is json:

JavaScript

Well I created 3 simple classes:

  1. class XXX… private String result, status; …. getter & setter
  2. class Response… private String codiceCase, guidCase; … getter & setter
  3. class ErrorManagement…private String errorCode, errorDescription;… getter & setter But when I populate with my mock, the json is always formed with the class field that I don’t care for example:
JavaScript

How can I get only 2 of the 3 classes returned as json in my mock? Thanks for your help.

Advertisement

Answer

I suppose you’re using Jackson to deserialize JSON as this is – I think – the default for spring.

With Jackson you can annotate the model class to omit null values in the JSON string representation:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement