Search in sources :

Example 16 with ProtobufField

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

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 17 with ProtobufField

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

the class ParamSerializer method serialize.

@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
    gen.writeStartObject();
    ProtobufGenerator protobufGenerator = (ProtobufGenerator) gen;
    Iterator<ProtobufField> iter = protobufGenerator.getSchema().getRootType().fields().iterator();
    Object[] values = (Object[]) value;
    for (Object value1 : values) {
        gen.writeObjectField(iter.next().name, value1);
    }
    gen.writeEndObject();
}
Also used : ProtobufGenerator(com.fasterxml.jackson.dataformat.protobuf.ProtobufGenerator) ProtobufField(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField)

Example 18 with ProtobufField

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

the class ResultSerializer method serialize.

@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
    gen.writeStartObject();
    ProtobufGenerator protobufGenerator = (ProtobufGenerator) gen;
    ProtobufField field = protobufGenerator.getSchema().getRootType().firstField();
    gen.writeObjectField(field.name, value);
    gen.writeEndObject();
}
Also used : ProtobufGenerator(com.fasterxml.jackson.dataformat.protobuf.ProtobufGenerator) ProtobufField(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField)

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