Search in sources :

Example 1 with DemoRequest2

use of com.alipay.sofa.rpc.codec.jackson.model.DemoRequest2 in project sofa-rpc by sofastack.

the class JacksonSerializerTest method testJacksonFeature.

@Test
public void testJacksonFeature() throws UnsupportedEncodingException {
    try {
        JacksonSerializer serializer = new JacksonSerializer();
        serializer.decode(new ByteArrayWrapperByteBuf("{\"a\":1}".getBytes("UTF-8")), DemoRequest.class, null);
        Assert.fail();
    } catch (SofaRpcException e) {
    // ok
    } catch (Throwable e) {
        Assert.fail();
    }
    try {
        JacksonSerializer serializer = new JacksonSerializer();
        serializer.encode(new DemoRequest2(), null);
        Assert.fail();
    } catch (SofaRpcException e) {
    // ok
    } catch (Throwable e) {
        Assert.fail();
    }
    System.setProperty("sofa.rpc.codec.jackson.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES", "false");
    JacksonSerializer serializer = new JacksonSerializer();
    serializer.decode(new ByteArrayWrapperByteBuf("{\"a\":1}".getBytes("UTF-8")), DemoRequest.class, null);
    System.setProperty("sofa.rpc.codec.jackson.SerializationFeature.FAIL_ON_EMPTY_BEANS", "false");
    serializer = new JacksonSerializer();
    serializer.encode(new DemoRequest2(), null);
    System.setProperty("sofa.rpc.codec.jackson.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES", "true");
    System.setProperty("sofa.rpc.codec.jackson.SerializationFeature.FAIL_ON_EMPTY_BEANS", "true");
}
Also used : DemoRequest2(com.alipay.sofa.rpc.codec.jackson.model.DemoRequest2) ByteArrayWrapperByteBuf(com.alipay.sofa.rpc.transport.ByteArrayWrapperByteBuf) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) Test(org.junit.Test)

Aggregations

DemoRequest2 (com.alipay.sofa.rpc.codec.jackson.model.DemoRequest2)1 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)1 ByteArrayWrapperByteBuf (com.alipay.sofa.rpc.transport.ByteArrayWrapperByteBuf)1 Test (org.junit.Test)1