Skip to content

Commit

Permalink
♻️ NullSerializerProvider保留原默认行为,下游代码无需因此添加配置
Browse files Browse the repository at this point in the history
  • Loading branch information
evil0th authored and Hccake committed Apr 12, 2024
1 parent a8180cb commit 82a159b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public class NullSerializerProvider extends DefaultSerializerProvider {

private static final long serialVersionUID = 1L;

private boolean writeNullStringValuesAsQuotes = false;
private boolean writeNullStringValuesAsQuotes = true;

private boolean writeNullMapValuesAsBraces = false;
private boolean writeNullMapValuesAsBraces = true;

private boolean writeNullArrayValuesAsBrackets = false;
private boolean writeNullArrayValuesAsBrackets = true;

public NullSerializerProvider() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
return builder -> {
if (null != this.jacksonProperties.getSerialization()) {
JacksonProperties.Serialization serialization = this.jacksonProperties.getSerialization();
final boolean writeNullStringValuesAsQuotes = serialization.isWriteNullStringValuesAsQuotes();
final boolean writeNullMapValuesAsBraces = serialization.isWriteNullMapValuesAsBraces();
final boolean writeNullArrayValuesAsBrackets = serialization.isWriteNullArrayValuesAsBrackets();

final NullSerializerProvider nullSerializerProvider = new NullSerializerProvider();
nullSerializerProvider.setWriteNullStringValuesAsQuotes(writeNullStringValuesAsQuotes);
nullSerializerProvider.setWriteNullMapValuesAsBraces(writeNullMapValuesAsBraces);
nullSerializerProvider.setWriteNullArrayValuesAsBrackets(writeNullArrayValuesAsBrackets);
nullSerializerProvider
.setWriteNullStringValuesAsQuotes(serialization.isWriteNullStringValuesAsQuotes());
nullSerializerProvider.setWriteNullMapValuesAsBraces(serialization.isWriteNullMapValuesAsBraces());
nullSerializerProvider
.setWriteNullArrayValuesAsBrackets(serialization.isWriteNullArrayValuesAsBrackets());
builder.postConfigurer(c -> c.setSerializerProvider(nullSerializerProvider));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ public static class Serialization {
/**
* null string -> ""
*/
private boolean writeNullStringValuesAsQuotes = false;
private boolean writeNullStringValuesAsQuotes = true;

/**
* null map -> {}
*/
private boolean writeNullMapValuesAsBraces = false;
private boolean writeNullMapValuesAsBraces = true;

/**
* null array -> []
*/
private boolean writeNullArrayValuesAsBrackets = false;
private boolean writeNullArrayValuesAsBrackets = true;

}

Expand Down

0 comments on commit 82a159b

Please sign in to comment.