Skip to content

Commit

Permalink
Add a simple test for JsonMapper.rebuild()
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 14, 2024
1 parent bf909b0 commit 09fd974
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static Builder builder(JsonFactory streamFactory) {
return new Builder(new JsonMapper(streamFactory));
}

public JsonMapper.Builder rebuild() {
public JsonMapper.Builder rebuild() {
// 09-Dec-2018, tatu: Not as good as what 3.0 has wrt immutability, but best approximation
// we have for 2.x
return new Builder(this.copy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.json.JsonWriteFeature;
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter;

import com.fasterxml.jackson.databind.cfg.EnumFeature;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.fasterxml.jackson.databind.introspect.VisibilityChecker;
import com.fasterxml.jackson.databind.json.JsonMapper;
Expand Down Expand Up @@ -267,6 +267,27 @@ public void testAnnotationIntrospectorCopying()
m2.getSerializationConfig().getAnnotationIntrospector().getClass());
}

/*
/**********************************************************
/* Test methods, JsonMapper.rebuild()
/**********************************************************
*/

@Test
public void jsonMapperRebuildTest()
{
JsonMapper m = JsonMapper.builder().build();
JsonMapper m2 = m.copy();
assertNotSame(m, m2);

JsonMapper m3 = m2.rebuild()
.propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
.enable(EnumFeature.WRITE_ENUMS_TO_LOWERCASE)
.build();
assertNotSame(m2, m3);
}

/*
/**********************************************************
/* Test methods, other
Expand Down

0 comments on commit 09fd974

Please sign in to comment.