You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Below code works with Jackson 2.8 version but with jackson 2.12x (Jackson-dataformat-ion), deserialization test case fails.
Also tried with intializing ionObject mapper by disabling native type ids but it didnt work.
IonObjectMapper m = new IonObjectMapper().disable(IonGenerator.Feature.USE_NATIVE_TYPE_ID);
Test case results are : Expected :is <ChildSelector(value=FareCard(elementFactor=FARE, fares=[FARE(type=MARGIN, value=5.00 USD, level=SINGLE)]))>
Actual :<ChildSelector(value=null)>
--- TestClass Code ---
import com.amazon.ion.IonValue;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.ion.EnumAsIonSymbolSerializer;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import com.fasterxml.jackson.core.type.TypeReference;
import javax.annotation.Nonnull;
import java.beans.ConstructorProperties;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collections;
public class Test {
private static final String TEST_SELECTOR_STR = "Child::{" +
"element_factor: FARE," +
"fares: [{ type: MARGIN, level: SINGLE, value: { amount: \"10.00\", currencyCode: \"USD\" } }]}";
private static final IonValue TEST_SELECTOR_ION = IonTestUtils.deserializeIon(TEST_SELECTOR_STR);
private static final ChildSelector<FareCard> TEST_SELECTOR = new ChildSelector<>(TEST_FARE_CARD);
private static final FareCard TEST_FARE_CARD = new FareCard(Element.FARE, Collections.singletonList(
Fare.marginFare(new Currency("10.00", "USD"))));
@Test
public void testDeserialize() throws Exception {
Rule<FareCard> rc = NoSQLIonValue.deserialize(TEST_SELECTOR_ION, new TypeReference<ChildSelector<FareCard>>() {});
assertThat(rc, is(TEST_SELECTOR));
}
@Test
public void testSerialize() throws Exception {
IonValue ion = NoSQLIonValue.serialize(TEST_SELECTOR);
assertThat(ion, is(TEST_SELECTOR_ION));
}
}
---NoSQLIonValue.java---
package com.jacksonissue;
import com.amazon.ion.IonList;
import com.amazon.ion.IonValue;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.dataformat.ion.IonGenerator;
import com.fasterxml.jackson.dataformat.ion.IonObjectMapper;
import com.fasterxml.jackson.dataformat.ion.ionvalue.IonValueModule;
import com.jacksonissue.NoSQLValue;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.core.JsonGenerator;
import com.netbeetle.jackson.ConstructorPropertiesAnnotationIntrospector;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class NoSQLIonValue {
public static <T> T deserialize(@Nonnull IonValue ionValue, TypeReference tr) {
return fMapper.readValue(ionValue, tr);
}
public static <T extends NoSQLValue> IonValue serialize(@Nonnull T obj) {
return fMapper.writeValueAsIonValue(obj);
}
private static IonObjectMapper fMapper = new IonObjectMapper();
static {
fMapper.setPropertyNamingStrategy(new NoSQLPropertyNamingStrategy());
// Lombok sticks @ConstructorProperties on generated constructors - this lets Jackson read it
fMapper.setConfig(fMapper.getDeserializationConfig().withAppendedAnnotationIntrospector(
new ConstructorPropertiesAnnotationIntrospector()));
fMapper.registerModule(new IonValueModule());
fMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
fMapper.enable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN);
fMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
}
Below code works with Jackson 2.8 version but with jackson 2.12x (Jackson-dataformat-ion), deserialization test case fails.
Also tried with intializing ionObject mapper by disabling native type ids but it didnt work.
IonObjectMapper m = new IonObjectMapper().disable(IonGenerator.Feature.USE_NATIVE_TYPE_ID);
Test case results are :
Expected :is <ChildSelector(value=FareCard(elementFactor=FARE, fares=[FARE(type=MARGIN, value=5.00 USD, level=SINGLE)]))>
Actual :<ChildSelector(value=null)>
--- TestClass Code ---
---NoSQLIonValue.java---
---Rule.java---
--- ChildSelector.java ---
---FareCard.java---
-- FARE.java --
-- Currency.java --
---Level.java ---
--Element.java--
--NoSQLValue.java--
-- IonTestUtils.java --
--sym--
The text was updated successfully, but these errors were encountered: