Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to use JACKSON serializer for domain object used for different services?
    primarykey
    data
    text
    <p>I have one domain object which is used for 2 different services as below :</p> <pre><code>public class PersonDetails { private String personId; private String personMaritalStatus; private String personFirstName; private String personLastName; // setters and getters ... } </code></pre> <p>and having two different services.</p> <p><strong>First One :</strong></p> <pre><code>public BaseResponse getClient(@QueryParam("id") @DefaultValue("-1") String id) { } </code></pre> <p>this service should return json as below :</p> <pre><code>{ "personId":12, "personMaritalStatus":"married", "personFirstname" :"abc", "personLastname":"pqr" } </code></pre> <p><strong>Second service :</strong> </p> <pre><code>public BaseResponse getClientName(@QueryParam("id") @DefaultValue("-1") String id) { } </code></pre> <p>this service should return json as below :</p> <pre><code>{"personFirstname" :"abc"} </code></pre> <p>So if I used <code>@JsonSerialize(using=PersonDetailsSerializer.class)</code> over domain object and serializer class will be as below :</p> <pre><code>public class PersonDetailsSerializerextends JsonSerializer&lt;PersonDetails&gt; { @Override public void serialize(PersonDetails personDetails, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField("personFirstname", personDetails.getpersonFirstName()); jsonGenerator.writeEndObject(); } } </code></pre> <p>then it impact response for getPerson service also. </p> <p>So how can I used service level serialization or is anyother way to handle this, using JACKSON...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload