1

I'm using Spring Boot 1.3.3 and created a REST controller to add a JSON object into Mongo DB collections.

The data to be added from the JSON object will be a subset of information received from the request. So i have created a JSON request object ( DTO ) and an entity object ( model ) to be stored in Mongo collection.

I'm facing an issue now as the JSON request object is populated with default values for integer ( 0 ) and boolean data types ( false ) even if these fields are not populated as part of the request message. I don't want to store these values in the database.

I have added " spring.jackson.serialization-inclusion=non-null " and " spring.jackson.serialization-inclusion=non-default " properties in my application.properties file but still the fields are populated with default values.
Could anyone please help me out in resolving this issue and bypass the default values. NOTE: It works fine for String data type as they would be NULL values by default if not created.

Thanks in advance

1
  • 1
    Hi All,The issue is now resolved by changing the primitive data types to their corresponding Wrapper Classes. ( Ex: from boolean to Boolean , int to Integer ). Commented Apr 15, 2016 at 9:47

2 Answers 2

2

String Attributes accept the null value while the primitive attributes have a default value for example 0 is default value for the int attributes.. to avoid having this values Use Integer instead.

Sign up to request clarification or add additional context in comments.

Comments

0

Please use this annotation above your fields in bean class with which you facing the problem and tell me your problem is solved.

'@JsonInclude(Include.NON_NULL)'

Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.