Search in sources :

Example 1 with IonObjectMapper

use of com.fasterxml.jackson.dataformat.ion.IonObjectMapper in project amazon-qldb-dmv-sample-java by aws-samples.

the class RegisterDriversLicense method registerNewDriversLicense.

/**
 * Register a new driver's license.
 *
 * @param txn
 *              The {@link TransactionExecutor} for lambda execute.
 * @param govId
 *              The government ID of the new owner.
 * @param license
 *              The new license to register.
 * @param personId
 *              The unique personId of the new owner.
 * @throws IllegalStateException if failed to convert document ID to an IonValue.
 */
public static void registerNewDriversLicense(final TransactionExecutor txn, final String govId, final DriversLicense license, final String personId) {
    try {
        if (personHadDriversLicense(txn, personId)) {
            log.info("Person with government ID '{}' already has a license! No new license added.", govId);
            return;
        }
        final String query = "INSERT INTO DriversLicense ?";
        log.info(new IonObjectMapper().writeValueAsIonValue(license).toPrettyString());
        final List<IonValue> parameters = Collections.singletonList(Constants.MAPPER.writeValueAsIonValue(license));
        txn.execute(query, parameters);
        Result result = queryDriversLicenseByPersonId(txn, govId);
        if (ScanTable.toIonStructs(result).size() > 0) {
            log.info("Problem occurred while inserting new license, please review the results.");
        } else {
            log.info("Successfully registered new driver.");
        }
    } catch (IOException ioe) {
        throw new IllegalStateException(ioe);
    }
}
Also used : IonValue(com.amazon.ion.IonValue) IOException(java.io.IOException) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Result(software.amazon.qldb.Result)

Example 2 with IonObjectMapper

use of com.fasterxml.jackson.dataformat.ion.IonObjectMapper in project jackson-dataformats-binary by FasterXML.

the class IonValueMapperTest method testPojo5WithSexpInArray.

@Test
public void testPojo5WithSexpInArray() throws Exception {
    IonObjectMapper mapper = IonObjectMapper.builder(ionF).propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE).disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build();
    String value = "{value:[([blah])], number:\"Random\"}";
    TestPojo5 test = mapper.readValue(ionSystem.singleValue(value), TestPojo5.class);
    assertNotNull(test);
    assertNotNull(test.number);
    assertEquals("Random", test.number);
    assertNotNull(test.value.get(0));
    assertRoundTrip(value, TestPojo5.class);
}
Also used : IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 3 with IonObjectMapper

use of com.fasterxml.jackson.dataformat.ion.IonObjectMapper in project jackson-dataformats-binary by FasterXML.

the class IonValueMapperTest method testPojo4WithSexpInArrayIgnored.

@Test
public void testPojo4WithSexpInArrayIgnored() throws Exception {
    IonObjectMapper mapper = IonObjectMapper.builder(ionF).propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE).disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build();
    String value = "{value:[([])], number:\"Random\"}";
    TestPojo4 test = mapper.readValue(ionSystem.singleValue(value), TestPojo4.class);
    assertNotNull(test);
    assertNotNull(test.number);
    assertEquals("Random", test.number);
}
Also used : IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 4 with IonObjectMapper

use of com.fasterxml.jackson.dataformat.ion.IonObjectMapper in project jackson-dataformats-binary by FasterXML.

the class IonTimestampInstantDeserializerTest method testDeserializationWithTypeInfo01.

/*
     **********************************************************************
     * Deserialization of actuals with type info
     **********************************************************************
     */
@Test
public void testDeserializationWithTypeInfo01() throws Exception {
    Instant expected = Instant.ofEpochSecond(123456789L, 183917322);
    IonObjectMapper m = newMapperBuilder().enable(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS).addMixIn(Temporal.class, MockObjectConfiguration.class).build();
    Temporal actual = m.readValue("[\"" + Instant.class.getName() + "\",123456789.183917322]", Temporal.class);
    assertTrue("The actual should be an Instant.", actual instanceof Instant);
    assertEquals("The value is not correct.", expected, actual);
}
Also used : Temporal(java.time.temporal.Temporal) Instant(java.time.Instant) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 5 with IonObjectMapper

use of com.fasterxml.jackson.dataformat.ion.IonObjectMapper in project jackson-dataformats-binary by FasterXML.

the class IonTimestampInstantDeserializerTest method testDeserializationWithTypeInfo04.

@Test
public void testDeserializationWithTypeInfo04() throws Exception {
    Instant expected = Instant.now();
    IonObjectMapper m = newMapperBuilder().addMixIn(Temporal.class, MockObjectConfiguration.class).build();
    Timestamp timestamp = TimestampUtils.toTimestamp(expected, ZoneOffset.UTC);
    Temporal actual = m.readValue("[\"" + Instant.class.getName() + "\"," + timestamp.toString() + "]", Temporal.class);
    assertTrue("The actual should be an Instant.", actual instanceof Instant);
    assertEquals("The value is not correct.", expected, actual);
}
Also used : Temporal(java.time.temporal.Temporal) Instant(java.time.Instant) Timestamp(com.amazon.ion.Timestamp) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Aggregations

IonObjectMapper (com.fasterxml.jackson.dataformat.ion.IonObjectMapper)72 Test (org.junit.Test)70 Temporal (java.time.temporal.Temporal)24 Instant (java.time.Instant)20 OffsetDateTime (java.time.OffsetDateTime)20 ZonedDateTime (java.time.ZonedDateTime)20 Timestamp (com.amazon.ion.Timestamp)8 IonTimestamp (com.amazon.ion.IonTimestamp)4 IonValue (com.amazon.ion.IonValue)4 IonDecimal (com.amazon.ion.IonDecimal)1 IonInt (com.amazon.ion.IonInt)1 IonSystem (com.amazon.ion.IonSystem)1 DatabindException (com.fasterxml.jackson.databind.DatabindException)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 BeforeClass (org.junit.BeforeClass)1 Result (software.amazon.qldb.Result)1