Add visibility support to Jackson2ObjectMapperBuilder
Issue: SPR-16411
This commit is contained in:
committed by
Sebastien Deleuze
parent
7fd0cac6f2
commit
48c3fa9908
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,8 +32,10 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
||||
import com.fasterxml.jackson.annotation.JsonFilter;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
@@ -87,6 +89,7 @@ import static org.junit.Assert.assertTrue;
|
||||
* Test class for {@link Jackson2ObjectMapperBuilder}.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Jackson2ObjectMapperBuilderTests {
|
||||
@@ -499,6 +502,19 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void visibility() throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.visibility(PropertyAccessor.GETTER, Visibility.NONE)
|
||||
.visibility(PropertyAccessor.FIELD, Visibility.ANY)
|
||||
.build();
|
||||
|
||||
String json = objectMapper.writeValueAsString(new JacksonVisibilityBean());
|
||||
assertThat(json, containsString("property1"));
|
||||
assertThat(json, containsString("property2"));
|
||||
assertThat(json, not(containsString("property3")));
|
||||
}
|
||||
|
||||
public static class CustomIntegerModule extends Module {
|
||||
|
||||
@Override
|
||||
@@ -585,4 +601,16 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
}
|
||||
|
||||
public static class JacksonVisibilityBean {
|
||||
|
||||
private String property1;
|
||||
|
||||
public String property2;
|
||||
|
||||
public String getProperty3() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user