Search in sources :

Example 1 with ProtobufField

use of com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField in project java-chassis by ServiceComb.

the class AbstractFieldCodec method initFieldMap.

private void initFieldMap(ProtobufSchema schema, Type[] types) {
    Iterator<ProtobufField> fieldIter = schema.getRootType().fields().iterator();
    for (int idx = 0; idx < schema.getRootType().getFieldCount(); idx++) {
        JavaType type = TypeFactory.defaultInstance().constructType(types[idx]);
        ProtobufField field = fieldIter.next();
        ReaderHelpData helpData = new ReaderHelpData();
        helpData.index = idx;
        helpData.deser = ((CseObjectReader) reader).findDeserializer(type);
        readerHelpDataMap.put(field.name, helpData);
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) ProtobufField(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField)

Example 2 with ProtobufField

use of com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField in project java-chassis by ServiceComb.

the class TestAbstractFieldCodec method testInit.

@Test
public void testInit() {
    ProtobufField[] protobufFieldArray = new ProtobufField[5];
    FieldElement rawType = null;
    FieldType type = FieldType.STRING;
    ProtobufField p = new ProtobufField(rawType, type);
    protobufFieldArray[0] = p;
    Type[] types = new Type[1];
    types[0] = Integer.TYPE;
    Mockito.when(schema.getRootType()).thenReturn(Mockito.mock(ProtobufMessage.class));
    Mockito.when(schema.getRootType().getFieldCount()).thenReturn(1);
    Mockito.when(schema.getRootType().fields()).thenReturn(Arrays.asList(protobufFieldArray));
    abstractFieldCodec.init(schema, types);
    Assert.assertNotNull(abstractFieldCodec.readerHelpDataMap.get("UNKNOWN"));
}
Also used : ProtobufMessage(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufMessage) FieldType(com.fasterxml.jackson.dataformat.protobuf.schema.FieldType) Type(java.lang.reflect.Type) FieldElement(com.fasterxml.jackson.dataformat.protobuf.protoparser.protoparser.FieldElement) ProtobufField(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField) FieldType(com.fasterxml.jackson.dataformat.protobuf.schema.FieldType) Test(org.junit.Test)

Example 3 with ProtobufField

use of com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField in project java-chassis by ServiceComb.

the class TestParamFieldCodec method testInit.

@Test
public void testInit() {
    Assert.assertNotNull(paramFieldCodec);
    ProtobufField[] protobufFieldArray = new ProtobufField[5];
    FieldElement rawType = null;
    FieldType type = FieldType.STRING;
    ProtobufField p = new ProtobufField(rawType, type);
    protobufFieldArray[0] = p;
    Type[] types = new Type[10];
    types[0] = Integer.TYPE;
    Mockito.when(schema.getRootType()).thenReturn(Mockito.mock(ProtobufMessage.class));
    Mockito.when(schema.getRootType().getFieldCount()).thenReturn(1);
    Mockito.when(schema.getRootType().fields()).thenReturn(Arrays.asList(protobufFieldArray));
    Assert.assertNull(paramFieldCodec.reader);
    Assert.assertNull(paramFieldCodec.writer);
    paramFieldCodec.init(schema, types);
    Assert.assertNotNull(paramFieldCodec.reader);
    Assert.assertNotNull(paramFieldCodec.writer);
}
Also used : ProtobufMessage(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufMessage) FieldType(com.fasterxml.jackson.dataformat.protobuf.schema.FieldType) Type(java.lang.reflect.Type) FieldElement(com.fasterxml.jackson.dataformat.protobuf.protoparser.protoparser.FieldElement) ProtobufField(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField) FieldType(com.fasterxml.jackson.dataformat.protobuf.schema.FieldType) Test(org.junit.Test)

Example 4 with ProtobufField

use of com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField in project java-chassis by ServiceComb.

the class TestResultFieldCodec method testInit.

@Test
public void testInit() {
    Assert.assertNotNull(resultFieldCodec);
    ProtobufField[] protobufFieldArray = new ProtobufField[5];
    FieldElement rawType = null;
    FieldType type = FieldType.STRING;
    ProtobufField p = new ProtobufField(rawType, type);
    protobufFieldArray[0] = p;
    Type[] types = new Type[10];
    types[0] = Integer.TYPE;
    Mockito.when(schema.getRootType()).thenReturn(Mockito.mock(ProtobufMessage.class));
    Mockito.when(schema.getRootType().getFieldCount()).thenReturn(1);
    Mockito.when(schema.getRootType().fields()).thenReturn(Arrays.asList(protobufFieldArray));
    Assert.assertNull(resultFieldCodec.reader);
    Assert.assertNull(resultFieldCodec.writer);
    resultFieldCodec.init(schema, types);
    Assert.assertNotNull(resultFieldCodec.reader);
    Assert.assertNotNull(resultFieldCodec.writer);
}
Also used : ProtobufMessage(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufMessage) FieldType(com.fasterxml.jackson.dataformat.protobuf.schema.FieldType) Type(java.lang.reflect.Type) FieldElement(com.fasterxml.jackson.dataformat.protobuf.protoparser.protoparser.FieldElement) ProtobufField(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField) FieldType(com.fasterxml.jackson.dataformat.protobuf.schema.FieldType) Test(org.junit.Test)

Example 5 with ProtobufField

use of com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField in project java-chassis by ServiceComb.

the class TestStandardParamCodec method testInit.

@Test
public void testInit() {
    Assert.assertNotNull(standardParamCodec);
    ProtobufField[] protobufFieldArray = new ProtobufField[5];
    FieldElement rawType = null;
    FieldType type = FieldType.STRING;
    ProtobufField p = new ProtobufField(rawType, type);
    protobufFieldArray[0] = p;
    Type[] types = new Type[1];
    types[0] = Integer.TYPE;
    Mockito.when(schema.getSchemaType()).thenReturn(FORMAT_NAME_PROTOBUF);
    Mockito.when(schema.getRootType()).thenReturn(Mockito.mock(ProtobufMessage.class));
    Mockito.when(schema.getRootType().getFieldCount()).thenReturn(1);
    Mockito.when(schema.getRootType().fields()).thenReturn(Arrays.asList(protobufFieldArray));
    Assert.assertNull(standardParamCodec.writer);
    Assert.assertNull(standardParamCodec.reader);
    standardParamCodec.init(schema, types);
    Assert.assertNotNull(standardParamCodec.writer);
    Assert.assertNotNull(standardParamCodec.reader);
}
Also used : ProtobufMessage(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufMessage) FieldType(com.fasterxml.jackson.dataformat.protobuf.schema.FieldType) Type(java.lang.reflect.Type) FieldElement(com.fasterxml.jackson.dataformat.protobuf.protoparser.protoparser.FieldElement) ProtobufField(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField) FieldType(com.fasterxml.jackson.dataformat.protobuf.schema.FieldType) Test(org.junit.Test)

Aggregations

ProtobufField (com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField)18 ProtobufMessage (com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufMessage)12 Test (org.junit.Test)12 FieldElement (com.fasterxml.jackson.dataformat.protobuf.protoparser.protoparser.FieldElement)10 FieldType (com.fasterxml.jackson.dataformat.protobuf.schema.FieldType)10 Type (java.lang.reflect.Type)10 ProtobufGenerator (com.fasterxml.jackson.dataformat.protobuf.ProtobufGenerator)6 JavaType (com.fasterxml.jackson.databind.JavaType)2 SerializerProvider (com.fasterxml.jackson.databind.SerializerProvider)2 ProtobufSchema (com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 MockUp (mockit.MockUp)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1