Search in sources :

Example 6 with IonTimestamp

use of com.amazon.ion.IonTimestamp in project ion-java by amzn.

the class IonReaderTextSystemX method getIonValue.

public IonValue getIonValue(IonSystem sys) {
    if (isNullValue()) {
        switch(_value_type) {
            case NULL:
                return sys.newNull();
            case BOOL:
                return sys.newNullBool();
            case INT:
                return sys.newNullInt();
            case FLOAT:
                return sys.newNullFloat();
            case DECIMAL:
                return sys.newNullDecimal();
            case TIMESTAMP:
                return sys.newNullTimestamp();
            case SYMBOL:
                return sys.newNullSymbol();
            case STRING:
                return sys.newNullString();
            case CLOB:
                return sys.newNullClob();
            case BLOB:
                return sys.newNullBlob();
            case LIST:
                return sys.newNullList();
            case SEXP:
                return sys.newNullSexp();
            case STRUCT:
                return sys.newNullString();
            default:
                throw new IonException("unrecognized type encountered");
        }
    }
    switch(_value_type) {
        case NULL:
            return sys.newNull();
        case BOOL:
            return sys.newBool(booleanValue());
        case INT:
            return sys.newInt(longValue());
        case FLOAT:
            return sys.newFloat(doubleValue());
        case DECIMAL:
            return sys.newDecimal(decimalValue());
        case TIMESTAMP:
            IonTimestamp t = sys.newNullTimestamp();
            Timestamp ti = timestampValue();
            t.setValue(ti);
            return t;
        case SYMBOL:
            return sys.newSymbol(stringValue());
        case STRING:
            return sys.newString(stringValue());
        case CLOB:
            IonClob clob = sys.newNullClob();
            // FIXME inefficient: both newBytes and setBytes copy the data
            clob.setBytes(newBytes());
            return clob;
        case BLOB:
            IonBlob blob = sys.newNullBlob();
            // FIXME inefficient: both newBytes and setBytes copy the data
            blob.setBytes(newBytes());
            return blob;
        case LIST:
            IonList list = sys.newNullList();
            fillContainerList(sys, list);
            return list;
        case SEXP:
            IonSexp sexp = sys.newNullSexp();
            fillContainerList(sys, sexp);
            return sexp;
        case STRUCT:
            IonStruct struct = sys.newNullStruct();
            fillContainerStruct(sys, struct);
            return struct;
        default:
            throw new IonException("unrecognized type encountered");
    }
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonSexp(com.amazon.ion.IonSexp) IonException(com.amazon.ion.IonException) IonTimestamp(com.amazon.ion.IonTimestamp) IonList(com.amazon.ion.IonList) IonClob(com.amazon.ion.IonClob) IonBlob(com.amazon.ion.IonBlob) Timestamp(com.amazon.ion.Timestamp) IonTimestamp(com.amazon.ion.IonTimestamp)

Example 7 with IonTimestamp

use of com.amazon.ion.IonTimestamp in project ion-java by amzn.

the class IonWriterSystemTree method writeTimestamp.

public void writeTimestamp(Timestamp value) throws IOException {
    IonTimestamp v = _factory.newTimestamp(value);
    append(v);
}
Also used : IonTimestamp(com.amazon.ion.IonTimestamp)

Example 8 with IonTimestamp

use of com.amazon.ion.IonTimestamp in project ion-java by amzn.

the class _Private_CurriedValueFactory method newTimestamp.

public IonTimestamp newTimestamp(Timestamp value) {
    IonTimestamp v = myFactory.newTimestamp(value);
    handle(v);
    return v;
}
Also used : IonTimestamp(com.amazon.ion.IonTimestamp)

Example 9 with IonTimestamp

use of com.amazon.ion.IonTimestamp in project ion-java by amzn.

the class _Private_CurriedValueFactory method newNullTimestamp.

// -------------------------------------------------------------------------
public IonTimestamp newNullTimestamp() {
    IonTimestamp v = myFactory.newNullTimestamp();
    handle(v);
    return v;
}
Also used : IonTimestamp(com.amazon.ion.IonTimestamp)

Example 10 with IonTimestamp

use of com.amazon.ion.IonTimestamp in project jackson-dataformats-binary by FasterXML.

the class IonTimestampInstantSerializerTest method testSerializationAsString01.

@Test
public void testSerializationAsString01() throws Exception {
    IonObjectMapper mapper = newMapperBuilder().disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).build();
    Instant date = Instant.ofEpochSecond(0L);
    Timestamp value = ((IonTimestamp) mapper.writeValueAsIonValue(date)).timestampValue();
    assertEquals("The value is not correct.", TimestampUtils.toTimestamp(date, ZoneOffset.UTC), value);
}
Also used : IonTimestamp(com.amazon.ion.IonTimestamp) Instant(java.time.Instant) Timestamp(com.amazon.ion.Timestamp) IonTimestamp(com.amazon.ion.IonTimestamp) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Aggregations

IonTimestamp (com.amazon.ion.IonTimestamp)15 Timestamp (com.amazon.ion.Timestamp)5 Test (org.junit.Test)5 IonStruct (com.amazon.ion.IonStruct)4 IonObjectMapper (com.fasterxml.jackson.dataformat.ion.IonObjectMapper)4 Instant (java.time.Instant)4 IonInt (com.amazon.ion.IonInt)3 IonBlob (com.amazon.ion.IonBlob)2 IonBool (com.amazon.ion.IonBool)2 IonClob (com.amazon.ion.IonClob)2 IonFloat (com.amazon.ion.IonFloat)2 IonList (com.amazon.ion.IonList)2 IonSexp (com.amazon.ion.IonSexp)2 IonString (com.amazon.ion.IonString)2 IonSymbol (com.amazon.ion.IonSymbol)2 BlobTest (com.amazon.ion.BlobTest)1 ClobTest (com.amazon.ion.ClobTest)1 IntTest (com.amazon.ion.IntTest)1 IonDecimal (com.amazon.ion.IonDecimal)1 IonException (com.amazon.ion.IonException)1