From d23bacb8497280007f5770e0f47ffc9fae126b34 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 26 Aug 2023 13:10:39 +0900 Subject: [PATCH 1/4] Remove unnecessary unboxing --- .../jackson/databind/ser/BeanSerializerFactory.java | 2 +- .../jackson/databind/ser/std/ArraySerializerBase.java | 2 +- .../databind/ser/std/DateTimeSerializerBase.java | 2 +- .../jackson/databind/ser/std/EnumSerializer.java | 2 +- .../jackson/databind/ser/std/MapSerializer.java | 2 +- .../jackson/databind/ser/std/NumberSerializers.java | 10 +++++----- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java b/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java index 5eddc195be..6fff2834fa 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java @@ -790,7 +790,7 @@ protected void removeIgnorableTypes(SerializationConfig config, BeanDescription ignores.put(type, result); } // lotsa work, and yes, it is ignorable type, so: - if (result.booleanValue()) { + if (result) { it.remove(); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ArraySerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ArraySerializerBase.java index d6f3fa6845..affecab376 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ArraySerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ArraySerializerBase.java @@ -149,6 +149,6 @@ protected final boolean _shouldUnwrapSingle(SerializerProvider provider) { if (_unwrapSingle == null) { return provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED); } - return _unwrapSingle.booleanValue(); + return _unwrapSingle; } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java index 07b0d46644..c5f1f981ad 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java @@ -183,7 +183,7 @@ public abstract void serialize(T value, JsonGenerator gen, SerializerProvider se protected boolean _asTimestamp(SerializerProvider serializers) { if (_useTimestamp != null) { - return _useTimestamp.booleanValue(); + return _useTimestamp; } if (_customFormat == null) { if (serializers != null) { diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java index 92af029b56..efc8d67ee2 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java @@ -251,7 +251,7 @@ public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType t protected final boolean _serializeAsIndex(SerializerProvider serializers) { if (_serializeAsIndex != null) { - return _serializeAsIndex.booleanValue(); + return _serializeAsIndex; } return serializers.isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java index b4a219f4ad..87404fe5df 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java @@ -546,7 +546,7 @@ public JsonSerializer createContextual(SerializerProvider provider, if (format != null) { Boolean B = format.getFeature(JsonFormat.Feature.WRITE_SORTED_MAP_ENTRIES); if (B != null) { - sortKeys = B.booleanValue(); + sortKeys = B; } } MapSerializer mser = withResolved(property, keySer, ser, ignored, included, sortKeys); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java index 01ed61fcb3..c81c2ba2e2 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java @@ -131,7 +131,7 @@ public ShortSerializer() { @Override public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException { - gen.writeNumber(((Short) value).shortValue()); + gen.writeNumber((Short) value); } } @@ -154,7 +154,7 @@ public IntegerSerializer(Class type) { @Override public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException { - gen.writeNumber(((Integer) value).intValue()); + gen.writeNumber((Integer) value); } // IMPORTANT: copied from `NonTypedScalarSerializerBase` @@ -196,7 +196,7 @@ public LongSerializer(Class cls) { @Override public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException { - gen.writeNumber(((Long) value).longValue()); + gen.writeNumber((Long) value); } } @@ -211,7 +211,7 @@ public FloatSerializer() { @Override public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException { - gen.writeNumber(((Float) value).floatValue()); + gen.writeNumber((Float) value); } } @@ -232,7 +232,7 @@ public DoubleSerializer(Class cls) { public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException { - gen.writeNumber(((Double) value).doubleValue()); + gen.writeNumber((Double) value); } // IMPORTANT: copied from `NonTypedScalarSerializerBase` From b2113f2c3553349a255ac20b03cb6adc04f9f0b2 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 26 Aug 2023 13:13:03 +0900 Subject: [PATCH 2/4] Remove unnecessary comparison --- .../jackson/databind/ser/DefaultSerializerProvider.java | 3 --- .../jackson/databind/ser/std/BeanSerializerBase.java | 8 +++----- .../fasterxml/jackson/databind/ser/std/StdSerializer.java | 4 ++-- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java index 2c9f0ac6f9..8d029c5def 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java @@ -617,9 +617,6 @@ protected Impl(SerializerProvider src, SerializationConfig config, @Override public DefaultSerializerProvider copy() { - if (getClass() != Impl.class) { - return super.copy(); - } return new Impl(this); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java index 5ce01c9933..8f4267003d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java @@ -550,11 +550,9 @@ public JsonSerializer createContextual(SerializerProvider provider, } // Or change Filter Id in use? Object filterId = intr.findFilterId(accessor); - if (filterId != null) { - // but only consider case of adding a new filter id (no removal via annotation) - if (_propertyFilterId == null || !filterId.equals(_propertyFilterId)) { - newFilterId = filterId; - } + // but only consider case of adding a new filter id (no removal via annotation) + if (filterId != null && !filterId.equals(_propertyFilterId)) { + newFilterId = filterId; } } // either way, need to resolve serializer: diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java index 448760836f..c8eec1c08a 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java @@ -144,7 +144,7 @@ public JsonNode getSchema(SerializerProvider provider, Type typeHint, boolean is { ObjectNode schema = (ObjectNode) getSchema(provider, typeHint); if (!isOptional) { - schema.put("required", !isOptional); + schema.put("required", true); } return schema; } @@ -166,7 +166,7 @@ protected ObjectNode createSchemaNode(String type, boolean isOptional) { ObjectNode schema = createSchemaNode(type); if (!isOptional) { - schema.put("required", !isOptional); + schema.put("required", true); } return schema; } From d48f9f68cf4f88145033c5eb609f6e11f6d778bc Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 26 Aug 2023 13:15:22 +0900 Subject: [PATCH 3/4] Removed unnecessary assignments --- .../jackson/databind/ser/BasicSerializerFactory.java | 8 ++------ .../jackson/databind/ser/impl/MapEntrySerializer.java | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java b/src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java index 7503eb742c..afb4e0e18d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java @@ -900,9 +900,7 @@ protected MapSerializer _checkMapContentInclusion(SerializerProvider prov, break; case CUSTOM: // new with 2.9 valueToSuppress = prov.includeFilterInstance(null, inclV.getContentFilter()); - if (valueToSuppress == null) { // is this legal? - suppressNulls = true; - } else { + if (valueToSuppress != null) { // is this legal? suppressNulls = prov.includeFilterSuppressNulls(valueToSuppress); } break; @@ -967,9 +965,7 @@ protected JsonSerializer buildMapEntrySerializer(SerializerProvider prov, break; case CUSTOM: valueToSuppress = prov.includeFilterInstance(null, inclV.getContentFilter()); - if (valueToSuppress == null) { // is this legal? - suppressNulls = true; - } else { + if (valueToSuppress != null) { // is this legal? suppressNulls = prov.includeFilterSuppressNulls(valueToSuppress); } break; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/MapEntrySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/MapEntrySerializer.java index 01b0ffc3c0..d013729436 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/MapEntrySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/MapEntrySerializer.java @@ -270,10 +270,8 @@ public JsonSerializer createContextual(SerializerProvider provider, } } - MapEntrySerializer mser = withResolved(property, keySer, ser, - valueToSuppress, suppressNulls); // but note: no (full) filtering or sorting (unlike Maps) - return mser; + return withResolved(property, keySer, ser, valueToSuppress, suppressNulls); } /* From 78b17fb6a25a02275fdc4efd6c83120fec2f4deb Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 26 Aug 2023 13:15:55 +0900 Subject: [PATCH 4/4] Simplify --- .../jackson/databind/ser/BeanSerializerFactory.java | 12 +++--------- .../jackson/databind/ser/std/IterableSerializer.java | 4 +--- .../jackson/databind/ser/std/UUIDSerializer.java | 7 ++----- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java b/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java index 6fff2834fa..0f70bd9717 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java @@ -802,15 +802,9 @@ protected void removeIgnorableTypes(SerializationConfig config, BeanDescription protected void removeSetterlessGetters(SerializationConfig config, BeanDescription beanDesc, List properties) { - Iterator it = properties.iterator(); - while (it.hasNext()) { - BeanPropertyDefinition property = it.next(); - // one caveat: only remove implicit properties; - // explicitly annotated ones should remain - if (!property.couldDeserialize() && !property.isExplicitlyIncluded()) { - it.remove(); - } - } + // one caveat: only remove implicit properties; + // explicitly annotated ones should remain + properties.removeIf(property -> !property.couldDeserialize() && !property.isExplicitlyIncluded()); } /** diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/IterableSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/IterableSerializer.java index 70d40be109..4116ef603b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/IterableSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/IterableSerializer.java @@ -50,9 +50,7 @@ public boolean hasSingleElement(Iterable value) { Iterator it = value.iterator(); if (it.hasNext()) { it.next(); - if (!it.hasNext()) { - return true; - } + return !it.hasNext(); } } return false; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/UUIDSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/UUIDSerializer.java index a281a906dd..09cfb205f5 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/UUIDSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/UUIDSerializer.java @@ -51,11 +51,8 @@ protected UUIDSerializer(Boolean asBinary) { public boolean isEmpty(SerializerProvider prov, UUID value) { // Null UUID is empty, so... - if (value.getLeastSignificantBits() == 0L - && value.getMostSignificantBits() == 0L) { - return true; - } - return false; + return value.getLeastSignificantBits() == 0L + && value.getMostSignificantBits() == 0L; } @Override