use of org.apache.servicecomb.foundation.protobuf.internal.model.Root in project java-chassis by ServiceComb.
the class Protostuff method deserialize.
@Override
public Object deserialize(byte[] bytes) throws IOException {
Input input = new ByteArrayInput(bytes, false);
Root result = new Root();
rootSchema.mergeFrom(input, result);
return result;
}
use of org.apache.servicecomb.foundation.protobuf.internal.model.Root in project java-chassis by ServiceComb.
the class TestAnySchema method pack.
@Test
public void pack() throws Throwable {
builder.setAny(Any.pack(ProtobufRoot.User.newBuilder().setName("n1").build()));
check();
Map<String, Object> map = new HashMap<>();
map.put(ProtoConst.JSON_ID_NAME, "User");
map.put("name", "n1");
Root root = new Root();
root.setAny(map);
Assert.assertArrayEquals(protobufBytes, rootSerializer.serialize(root));
}
use of org.apache.servicecomb.foundation.protobuf.internal.model.Root in project java-chassis by ServiceComb.
the class TestAnySchema method json_fromMapWithoutType.
@SuppressWarnings("unchecked")
@Test
public void json_fromMapWithoutType() throws Throwable {
Map<String, Object> map = new HashMap<>();
map.put("name", "n1");
Root root = new Root();
root.setAny(map);
scbRootBytes = rootSerializer.serialize(root);
root = rootDeserializer.deserialize(scbRootBytes);
Assert.assertThat(root.getAny(), Matchers.instanceOf(Map.class));
Assert.assertThat((Map<? extends String, ? extends String>) root.getAny(), Matchers.hasEntry("name", "n1"));
RootDeserializer<Map<String, Object>> deserializer = protoMapper.createRootDeserializer("Root", Map.class);
map = deserializer.deserialize(scbRootBytes);
Assert.assertThat((Map<? extends String, ? extends String>) map.get("any"), Matchers.hasEntry("name", "n1"));
}
use of org.apache.servicecomb.foundation.protobuf.internal.model.Root in project java-chassis by ServiceComb.
the class TestAnySchema method anys_json.
@Test
public void anys_json() throws IOException {
Root root = new Root();
root.setAnys(Arrays.asList("abc", "123"));
scbRootBytes = rootSerializer.serialize(root);
root = rootDeserializer.deserialize(scbRootBytes);
Assert.assertThat(root.getAnys(), Matchers.contains("abc", "123"));
}
use of org.apache.servicecomb.foundation.protobuf.internal.model.Root in project incubator-servicecomb-java-chassis by apache.
the class TestAnySchema method pack.
@Test
public void pack() throws Throwable {
builder.setAny(Any.pack(ProtobufRoot.User.newBuilder().setName("n1").build()));
check();
Map<String, Object> map = new HashMap<>();
map.put(ProtoConst.JSON_ID_NAME, "User");
map.put("name", "n1");
Root root = new Root();
root.setAny(map);
Assert.assertArrayEquals(protobufBytes, rootSerializer.serialize(root));
}
Aggregations