Skip to content

Commit

Permalink
Merge branch '2.15' into 2.16
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 25, 2023
2 parents 4dcd1ec + ffeb90b commit 9084d4f
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 27 deletions.
4 changes: 2 additions & 2 deletions ion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ SomeType otherValue = mapper.readValue(data, SomeType.class);

### java.time JSR 310

With version 2.12 (to be released in September 2020), there will be optional support for
Version 2.12 (released on November 28, 2020) added support for
(de)serializing some `java.time` classes directly from/to Ion timestamp values.
To enable it, you need to registed module `IonJavaTimeModule` like so:
To enable it, you need to register module `IonJavaTimeModule` like so:

```java
IonObjectMapper mapper = IonObjectMapper.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.Calendar;

import com.fasterxml.jackson.core.Base64Variant;
Expand Down Expand Up @@ -228,7 +229,7 @@ public JacksonFeatureSet<StreamWriteCapability> getWriteCapabilities() {
@Override
public void writeNumber(int value) throws IOException {
_verifyValueWrite("write numeric value");
_writer.writeInt((long)value);
_writer.writeInt(value);
}

@Override
Expand Down Expand Up @@ -256,7 +257,7 @@ public void writeNumber(double value) throws IOException {
@Override
public void writeNumber(float value) throws IOException {
_verifyValueWrite("write numeric value");
_writer.writeFloat((double) value);
_writer.writeFloat(value);
}

@Override
Expand Down Expand Up @@ -322,7 +323,7 @@ public void writeString(char[] buffer, int offset, int length) throws IOExceptio
@Override
public void writeUTF8String(byte[] buffer, int offset, int length) throws IOException {
// Ion doesn't have matching optimized method, so:
writeString(new String(buffer, offset, length, "UTF-8"));
writeString(new String(buffer, offset, length, StandardCharsets.UTF_8));
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public JsonDeserializer<T> createContextual(DeserializationContext ctxt, BeanPro

final JsonFormat.Value format = findFormatOverrides(ctxt, property, handledType());
if (format != null) {
return new IonTimestampInstantDeserializer<T>(this,
return new IonTimestampInstantDeserializer<>(this,
format.getFeature(Feature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE));
}
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ public void testNullFields() throws IOException
doTests(new Bean(), new IonObjectMapper());
}

private void doTests(Bean bean, IonObjectMapper mapper) throws IOException
{
private void doTests(Bean bean, IonObjectMapper mapper) {
for (RoundTrippers rt : RoundTrippers.values()) {
try
{
Expand All @@ -156,9 +155,9 @@ public void testIonRoot() throws IOException {
Bean bean = m.readValue(root, Bean.class);
assertNotNull(bean);
assertEquals(bean.a, "test");
assertTrue(bean.b == 0.25);
assertEquals(0.25, bean.b, 0.0);
assertArrayEquals(new byte[0], bean.data);
assertEquals(bean.state, true);
assertTrue(bean.state);
assertNotNull(bean.sub);
assertEquals("yellow", bean.sub.getValue());
assertEquals("testSymbol", bean.symbol);
Expand Down Expand Up @@ -211,7 +210,7 @@ private void _testRoundTrip(Bean bean, RoundTrippers rt, IonObjectMapper m) thro

assertNotNull(result);
assertEquals(bean.a, result.a);
assertTrue(bean.b == result.b);
assertEquals(bean.b, result.b, 0.0);
assertArrayEquals(bean.data, result.data);
assertEquals(bean.state, result.state);
if (bean.sub == null)
Expand All @@ -227,6 +226,6 @@ private void _testRoundTrip(Bean bean, RoundTrippers rt, IonObjectMapper m) thro
assertEquals(bean.enumVal, result.enumVal);
assertEquals(bean.bigDec, result.bigDec);
assertEquals(bean.bigInt, result.bigInt);
assertTrue(bean.f == result.f);
assertEquals(bean.f, result.f, 0.0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class IonGeneratorTest {
"}";

static {
final Map<String, String> map = new HashMap<String, String>();
final Map<String, String> map = new HashMap<>();
map.put("a", "A");
map.put("b", "B");
map.put("c", "C");
Expand Down Expand Up @@ -78,7 +78,7 @@ public void setUp() throws Exception {
@Test
public void testSimpleWrite() throws Exception {
joiGenerator.writeBoolean(true);
assertThat(output.get(0), is((IonValue)ionSystem.newBool(true)));
assertThat(output.get(0), is(ionSystem.newBool(true)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testGetNumberTypeAndValue() throws Exception {
IonParser decimalParser = new IonFactory().createParser(ionDecimal);
Assert.assertEquals(JsonToken.VALUE_NUMBER_FLOAT, decimalParser.nextToken());
Assert.assertEquals(JsonParser.NumberType.BIG_DECIMAL, decimalParser.getNumberType());
Assert.assertTrue(new BigDecimal("" + decimalValue).compareTo((BigDecimal)decimalParser.getNumberValue()) == 0);
Assert.assertEquals(0, new BigDecimal("" + decimalValue).compareTo((BigDecimal) decimalParser.getNumberValue()));

Double floatValue = Double.MAX_VALUE;
IonValue ionFloat = ion.newFloat(floatValue);
Expand All @@ -78,7 +78,7 @@ public void testGetNumberTypeAndValue() throws Exception {
IonParser bigDecimalParser = new IonFactory().createParser(ionBigDecimal);
Assert.assertEquals(JsonToken.VALUE_NUMBER_FLOAT, bigDecimalParser.nextToken());
Assert.assertEquals(JsonParser.NumberType.BIG_DECIMAL, bigDecimalParser.getNumberType());
Assert.assertTrue(bigDecimalValue.compareTo((BigDecimal)bigDecimalParser.getNumberValue()) == 0);
Assert.assertEquals(0, bigDecimalValue.compareTo((BigDecimal) bigDecimalParser.getNumberValue()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ public void testSelectivePolymorphism() throws IOException {
// to be chosen (and we expect that first id to be the most narrow type, ChildBeanSub).
Bean deserialized = mapper.readValue(serialized, Bean.class);

assertTrue(deserialized.child.getClass().equals(ChildBeanSub.class));
assertEquals(deserialized.child.getClass(), ChildBeanSub.class);
assertEquals(((ChildBeanSub) original.child).extraField, ((ChildBeanSub) deserialized.child).extraField);

// second, try deserializing with the wider type (ChildBean). We're losing data (extraField)
preferredTypeId = getClass().getCanonicalName() + "$ChildBean";
deserialized = mapper.readValue(serialized, Bean.class);

assertTrue(deserialized.child.getClass().equals(ChildBean.class));
assertEquals(deserialized.child.getClass(), ChildBean.class);
assertEquals(original.child.someField, deserialized.child.someField);

// third, try deserializing into an Object. The child node should deserialize, but immediately fail mapping.
Expand Down Expand Up @@ -319,7 +319,7 @@ class MultipleClassNameIdResolver extends ClassNameIdResolver implements Multipl

@Override
public String[] idsFromValue(Object value) {
List<String> ids = new ArrayList<String>();
List<String> ids = new ArrayList<>();
Class<?> cls = value.getClass();
while (null != cls) {
ids.add(super.idFromValueAndType(value, cls));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private void _writeSimple(JsonGenerator gen) throws IOException
gen.writeStartObject();
gen.writeStringField("a", "value");
gen.writeNumberField("b", 42);
((IonGenerator)gen).writeFieldName("c");
gen.writeFieldName("c");
((IonGenerator)gen).writeNull(IonType.INT);
gen.writeEndObject();
gen.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void verifyException(Throwable e, String match)
{
String msg = e.getMessage();
String lmsg = (msg == null) ? "" : msg.toLowerCase();
if (lmsg.indexOf(match.toLowerCase()) < 0) {
if (!lmsg.contains(match.toLowerCase())) {
fail("Expected an exception with a substrings ("+match+"): got one with message \""+msg+"\"");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static org.junit.Assert.assertEquals;
import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SNAKE_CASE;
import static org.junit.Assert.assertNull;

public class IonValueDeserializerTest {
private static class Data<T> {
Expand Down Expand Up @@ -200,7 +201,7 @@ public void testWithMissingProperty() throws IOException
String input2 = "{required:{}}";
MyBean deserializedBean2 = ionObjectMapper.readValue(input2, MyBean.class);
assertEquals(ionSystem.newEmptyStruct(), deserializedBean2.required);
assertEquals(null, deserializedBean2.optional);
assertNull(deserializedBean2.optional);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.fasterxml.jackson.dataformat.ion.ionvalue;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

Expand Down Expand Up @@ -86,7 +87,7 @@ public void testPojo1() throws Exception {
TestPojo1 t = ionValueMapper.parse(ionSystem.singleValue(value), TestPojo1.class);
assertEquals("yes", t.myString);
assertEquals("yes", t.mySymbol);
assertEquals(false, t.doesThisWork);
assertFalse(t.doesThisWork);
assertEquals(5, t.iHaveSomeOtherName);
assertEquals(ReturnCode.Success, t.imAnEnum);
assertEquals(Timestamp.valueOf("2010-01-01T06:00:00Z"), t.someTime);
Expand Down Expand Up @@ -166,7 +167,7 @@ public void testPojo2WithBlob() throws Exception {
public static class TestPojo3 {
public int expected;

protected Map<String, IonValue> other = new HashMap<String, IonValue>();
protected Map<String, IonValue> other = new HashMap<>();

// "any getter" needed for serialization
@JsonAnyGetter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void verifyException(Throwable e, String match)
{
String msg = e.getMessage();
String lmsg = (msg == null) ? "" : msg.toLowerCase();
if (lmsg.indexOf(match.toLowerCase()) < 0) {
if (!lmsg.contains(match.toLowerCase())) {
fail("Expected an exception with a substrings ("+match+"): got one with message \""+msg+"\"");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ private static void assertCorrectlyTypedAndFormed(final Subclass expectedSubclas
assertEquals(expectedSubclass, (Subclass) actualBaseclass);
}
private static void assertEquals(Subclass expected, Subclass actual) {
Assert.assertEquals(expected.someString, ((Subclass) actual).someString);
Assert.assertEquals(expected.anInt, ((Subclass) actual).anInt);
Assert.assertEquals(expected.someString, actual.someString);
Assert.assertEquals(expected.anInt, actual.anInt);
}

private static void assertEqualIonValues(IonValue expected, IonValue actual) {
Expand Down

0 comments on commit 9084d4f

Please sign in to comment.