You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Investigate manually handling JsonFlatten serialization instead of writing the object to a tree and mutating nodes. The following is code which was an initial investigation along with comments of its short-comings:
// Investigation into serializing the class ourselves to prevent string manipulation.// Code below doesn't handle the following:// - Null values are serialized without respecting ObjectMapper inclusion.// - JsonType information isn't included.if (defaultSerializerinstanceofBeanSerializer) {
BeanSerializerbeanSerializer = (BeanSerializer) defaultSerializer;
jgen.writeStartObject();
Iterator<PropertyWriter> writerIterator = beanSerializer.properties();
while (writerIterator.hasNext()) {
BeanPropertyWriterwriter = (BeanPropertyWriter) writerIterator.next();
StringjsonPropertyName = writer.getName();
if ((writer.getMember().hasAnnotation(JsonFlatten.class) || classHasJsonFlatten)
&& CHECK_IF_FLATTEN_PROPERTY_PATTERN.matcher(jsonPropertyName).matches()) {
String[] flatteningNames = SPLIT_FLATTEN_PROPERTY_PATTERN.split(jsonPropertyName);
jgen.writeFieldName(flatteningNames[0]);
jgen.writeStartObject();
for (inti = 1; i < flatteningNames.length - 1; i++) {
jgen.writeFieldName(flatteningNames[i]);
jgen.writeStartObject();
}
jgen.writeFieldName(flatteningNames[flatteningNames.length - 1]);
writeValue(jgen, writer, value);
for (inti = 1; i < flatteningNames.length - 1; i++) {
jgen.writeEndObject();
}
jgen.writeEndObject();
} else {
jgen.writeFieldName(jsonPropertyName);
writeValue(jgen, writer, value);
}
}
jgen.writeEndObject();
return;
}
privatevoidwriteValue(JsonGeneratorjgen, BeanPropertyWriterwriter, Objectvalue) {
try {
mapper.writeValue(jgen, writer.get(value));
} catch (Exceptione) {
throwlogger.logExceptionAsError(newUncheckedIOException(newJsonGenerationException(e, jgen)));
}
}
The text was updated successfully, but these errors were encountered:
Investigate manually handling
JsonFlatten
serialization instead of writing the object to a tree and mutating nodes. The following is code which was an initial investigation along with comments of its short-comings:The text was updated successfully, but these errors were encountered: