Skip to content

Commit

Permalink
disable fail on empty beans serializer (aws#293)
Browse files Browse the repository at this point in the history
Co-authored-by: Anuraag Agrawal <aanuraag@amazon.co.jp>
  • Loading branch information
willarmiros and Anuraag Agrawal authored Aug 5, 2021
1 parent d9d17ec commit a94a013
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.node.NullNode;
Expand Down Expand Up @@ -58,6 +59,7 @@ public abstract class EntityImpl implements Entity {
@Deprecated
protected static final ObjectMapper mapper = new ObjectMapper()
.findAndRegisterModules()
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES)
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,16 @@ void testDateSerialization() {
String expected = "{\"default\":{\"date\":1616559298000}}";
assertThat(serializedSeg).contains(expected);
}

@Test
void testUnknownClassSerialization() {
Segment seg = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test");
seg.putAws("coolService", new EmptyBean());
seg.end();
seg.serialize(); // Verify we don't crash here
}

static class EmptyBean {
String otherField = "cerealization";
}
}

0 comments on commit a94a013

Please sign in to comment.