Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package jackson
- import com.fasterxml.jackson.annotation.JsonInclude
- import com.fasterxml.jackson.databind.ObjectMapper
- import spock.lang.Specification
- class ObjectMapperTest extends Specification {
- def "should not include nulls"() {
- given:
- def json = '''
- {
- "a": {},
- "b": [],
- "c": "",
- "d": 0,
- "e": null
- }
- '''
- def obj = [
- "a": [:],
- "b": [],
- "c": "",
- "d": 0,
- "e": null
- ]
- def jsonMapper = new ObjectMapper()
- .setSerializationInclusion(JsonInclude.Include.NON_NULL)
- def tree = jsonMapper.readTree(json)
- when:
- def a1 = jsonMapper.writeValueAsString(tree)
- def a2 = jsonMapper.writeValueAsString(obj)
- then:
- a1 == a2
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement