Skip to content

Commit db30d44

Browse files
authored
use java 17 features (#747)
1 parent 9e3927f commit db30d44

23 files changed

Lines changed: 80 additions & 132 deletions

File tree

avro/src/main/java/tools/jackson/dataformat/avro/AvroAnnotationIntrospector.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public List<PropertyName> findPropertyAliases(MapperConfig<?> config, Annotated
8181
if (ann == null) {
8282
return null;
8383
}
84-
return Collections.singletonList(PropertyName.construct(ann.alias()));
84+
return List.of(PropertyName.construct(ann.alias()));
8585
}
8686

8787
protected PropertyName _findName(Annotated a)
@@ -100,8 +100,7 @@ public Boolean hasRequiredMarker(MapperConfig<?> config, AnnotatedMember m) {
100100

101101
@Override
102102
public JsonCreator.Mode findCreatorAnnotation(MapperConfig<?> config, Annotated a) {
103-
if (a instanceof AnnotatedConstructor) {
104-
AnnotatedConstructor constructor = (AnnotatedConstructor) a;
103+
if (a instanceof AnnotatedConstructor constructor) {
105104
// 09-Mar-2017, tatu: Ideally would allow mix-ins etc, but for now let's take
106105
// a short-cut here:
107106
Class<?> declClass = constructor.getDeclaringClass();

avro/src/main/java/tools/jackson/dataformat/avro/schema/AvroSchemaHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ public abstract class AvroSchemaHelper
5959
/**
6060
* Default stringable classes
6161
*/
62-
protected static final Set<Class<?>> STRINGABLE_CLASSES = new HashSet<>(Arrays.asList(
62+
protected static final Set<Class<?>> STRINGABLE_CLASSES = Set.of(
6363
URI.class, URL.class, File.class,
6464
BigInteger.class, BigDecimal.class,
6565
String.class
66-
));
66+
);
6767

6868
/**
6969
* Checks if a given type is "Stringable", that is one of the default
@@ -206,7 +206,7 @@ public static Schema typedSchema(Schema.Type nativeType, JavaType javaType) {
206206

207207
public static Schema anyNumberSchema()
208208
{
209-
return Schema.createUnion(Arrays.asList(
209+
return Schema.createUnion(List.of(
210210
Schema.create(Schema.Type.INT),
211211
Schema.create(Schema.Type.LONG),
212212
Schema.create(Schema.Type.DOUBLE)

avro/src/main/java/tools/jackson/dataformat/avro/schema/RecordVisitor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ protected Schema.Field schemaFieldForWriter(BeanProperty prop, boolean optional)
254254
ValueSerializer<?> ser = null;
255255

256256
// 23-Nov-2012, tatu: Ideally shouldn't need to do this but...
257-
if (prop instanceof BeanPropertyWriter) {
258-
BeanPropertyWriter bpw = (BeanPropertyWriter) prop;
257+
if (prop instanceof BeanPropertyWriter bpw) {
259258
ser = bpw.getSerializer();
260259
// 2-Mar-2017, bryan: AvroEncode annotation expects to have the schema used directly
261260
optional = optional && !(ser instanceof CustomEncodingSerializer); // Don't modify schema

avro/src/main/java/tools/jackson/dataformat/avro/ser/CustomEncodingSerializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public void serialize(T t, JsonGenerator jsonGenerator, SerializationContext ctx
3737
@Override
3838
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType type)
3939
{
40-
if (visitor instanceof VisitorFormatWrapperImpl) {
41-
((VisitorFormatWrapperImpl) visitor).expectAvroFormat(new AvroSchema(encoding.getSchema()));
40+
if (visitor instanceof VisitorFormatWrapperImpl wrapper) {
41+
wrapper.expectAvroFormat(new AvroSchema(encoding.getSchema()));
4242
} else {
4343
super.acceptJsonFormatVisitor(visitor, type);
4444
}

cbor/src/main/java/tools/jackson/dataformat/cbor/CBORParser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,8 @@ protected String _numberToName(int ch, boolean neg, TagList tags) throws Jackson
806806
}
807807

808808
Object str = stringRefs.stringRefs.get(i);
809-
if (str instanceof String) {
810-
return (String) str;
809+
if (str instanceof String s) {
810+
return s;
811811
}
812812
return new String((byte[]) str, UTF8);
813813
}
@@ -833,8 +833,8 @@ protected JsonToken _handleTaggedInt(TagList tags) throws JacksonException {
833833
}
834834

835835
Object str = stringRefs.stringRefs.get(_numberInt);
836-
if (str instanceof String) {
837-
_sharedString = (String) str;
836+
if (str instanceof String s) {
837+
_sharedString = s;
838838
return _updateToken(JsonToken.VALUE_STRING);
839839
}
840840
_binaryValue = (byte[]) str;

cbor/src/main/java/tools/jackson/dataformat/cbor/CBORSimpleValue.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public String toString() {
5353
public boolean equals(Object o)
5454
{
5555
if (o == this) return true;
56-
if (o instanceof CBORSimpleValue) {
57-
CBORSimpleValue other = (CBORSimpleValue) o;
56+
if (o instanceof CBORSimpleValue other) {
5857
return _value == other._value;
5958
}
6059
return false;

ion/src/main/java/tools/jackson/dataformat/ion/EnumAsIonSymbolSerializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public EnumAsIonSymbolSerializer() {
4242

4343
@Override
4444
public void serialize(Enum<?> value, JsonGenerator g, SerializationContext provider) {
45-
if (g instanceof IonGenerator) {
45+
if (g instanceof IonGenerator ionGenerator) {
4646
String valueString = provider.isEnabled(EnumFeature.WRITE_ENUMS_USING_TO_STRING)
4747
? value.toString()
4848
: value.name();
4949

50-
((IonGenerator) g).writeSymbol(valueString);
50+
ionGenerator.writeSymbol(valueString);
5151
} else {
5252
throw new StreamWriteException(g, "Can only use EnumAsIonSymbolSerializer with IonGenerator");
5353
}

ion/src/main/java/tools/jackson/dataformat/ion/IonGenerator.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ protected void _closeInput() throws IOException
148148
_destination.close();
149149
} else {
150150
if (isEnabled(StreamWriteFeature.FLUSH_PASSED_TO_STREAM)) {
151-
if (_destination instanceof Flushable) {
152-
((Flushable) _destination).flush();
151+
if (_destination instanceof Flushable flushable) {
152+
flushable.flush();
153153
}
154154
}
155155
}
@@ -692,8 +692,7 @@ public JsonGenerator writeStartSexp() throws JacksonException {
692692

693693
@Override
694694
public JsonGenerator writeTypeId(Object rawId) throws JacksonException {
695-
if (rawId instanceof String[]) {
696-
String[] ids = (String[]) rawId;
695+
if (rawId instanceof String[] ids) {
697696
for (String id : ids) {
698697
annotateNextValue(id);
699698
}

ion/src/main/java/tools/jackson/dataformat/ion/IonParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ protected void _closeInput() throws IOException {
166166
// should only close if manage the resource
167167
if (_ioContext.isResourceManaged()) {
168168
Object src = _ioContext.contentReference().getRawContent();
169-
if (src instanceof Closeable) {
169+
if (src instanceof Closeable closeable) {
170170
try {
171-
((Closeable) src).close();
171+
closeable.close();
172172
} catch (IOException e) {
173173
throw _wrapIOFailure(e);
174174
}

ion/src/main/java/tools/jackson/dataformat/ion/ionvalue/IonValueDeserializer.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public ValueDeserializer<?> createContextual(DeserializationContext ctxt, BeanPr
4848
public IonValue deserialize(JsonParser jp, DeserializationContext ctxt) throws JacksonException
4949
{
5050
Object embeddedObject = jp.getEmbeddedObject();
51-
if (embeddedObject instanceof IonValue) {
52-
return (IonValue) embeddedObject;
51+
if (embeddedObject instanceof IonValue ionValue) {
52+
return ionValue;
5353
}
5454
// We rely on the IonParser's IonSystem to wrap supported types into an IonValue
5555
if (!(jp instanceof IonParser)) {
@@ -58,8 +58,8 @@ public IonValue deserialize(JsonParser jp, DeserializationContext ctxt) throws J
5858
}
5959

6060
IonSystem ionSystem = ((IonParser) jp).getIonSystem();
61-
if (embeddedObject instanceof Timestamp) {
62-
return ionSystem.newTimestamp((Timestamp) embeddedObject);
61+
if (embeddedObject instanceof Timestamp timestamp) {
62+
return ionSystem.newTimestamp(timestamp);
6363
}
6464
if (embeddedObject instanceof byte[]) {
6565
// The parser provides no distinction between BLOB and CLOB, deserializing to a BLOB is the safest choice.
@@ -74,8 +74,7 @@ public Object getNullValue(DeserializationContext ctxt) throws JacksonException
7474
final JsonParser parser = ctxt.getParser();
7575
if (parser != null && parser.currentToken() != JsonToken.END_OBJECT) {
7676
final Object embeddedObj = parser.getEmbeddedObject();
77-
if (embeddedObj instanceof IonValue) {
78-
IonValue iv = (IonValue) embeddedObj;
77+
if (embeddedObj instanceof IonValue iv) {
7978
if (iv.isNullValue()) {
8079
if (IonType.isContainer(iv.getType())) {
8180
return iv;

0 commit comments

Comments
 (0)