Skip to content

Commit

Permalink
Clean up of Ion module (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
thetric authored Oct 25, 2023
1 parent bb3f600 commit ffeb90b
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion avro/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ abstractions.
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
<version>1.2.12</version>
<scope>test</scope>
</dependency>
<!-- For validating more complex comparisons -->
Expand Down
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
6 changes: 3 additions & 3 deletions ion/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!-- is to indicate to Gradle or any Gradle module metadata file consumer -->
<!-- that they should prefer consuming it instead. -->
<!-- do_not_remove: published-with-gradle-metadata -->
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformats-binary</artifactId>
Expand Down Expand Up @@ -85,8 +85,8 @@ tree model)
will have to use `moduleInfoFile` as anything else requires JDK 9+
-->
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
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 @@ -220,7 +221,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 @@ -248,7 +249,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 @@ -314,7 +315,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
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-base</artifactId>
Expand Down Expand Up @@ -46,11 +46,11 @@

<!-- for Reproducible Builds -->
<project.build.outputTimestamp>2023-10-13T00:29:34Z</project.build.outputTimestamp>

<!-- 20-Mar-2021, tatu: limit heap for tests to catch some
of "too big allocation" cases
SEE: https://www.jacoco.org/jacoco/trunk/doc/prepare-agent-mojo.html
for explanation on "argLine" property
for explanation on "argLine" property
-->
<argLine>-Xmx1024m</argLine>
</properties>
Expand Down

0 comments on commit ffeb90b

Please sign in to comment.