Package com.alibaba.json.bvt

Source Code of com.alibaba.json.bvt.ByteArrayFieldTest_2

package com.alibaba.json.bvt;

import java.io.UnsupportedEncodingException;

import junit.framework.Assert;
import junit.framework.TestCase;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.json.test.TestUtils;

public class ByteArrayFieldTest_2 extends TestCase {

    public void test_0() throws Exception {
        Entity entity = new Entity("中华人民共和国");
        String text = JSON.toJSONString(entity);
        JSONObject json = JSON.parseObject(text);
        Assert.assertEquals(TestUtils.encodeToBase64String(entity.getValue(), false), json.getString("value"));
       
        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertEquals("中华人民共和国", new String(entity2.getValue(), "UTF-8"));
    }

    public static class Entity {

        private byte[] value;

        public Entity(){

        }

        public Entity(String value) throws UnsupportedEncodingException{
            this.value = value.getBytes("UTF-8");
        }

        public byte[] getValue() {
            return value;
        }

        public void setValue(byte[] value) {
            this.value = value;
        }

    }
}
TOP

Related Classes of com.alibaba.json.bvt.ByteArrayFieldTest_2

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.
"Examples of org.apache.falcon.entity.store.ConfigurationStore">org.apache.falcon.entity.store.ConfigurationStore
  • org.apache.falcon.rerun.handler.LateRerunConsumer
  • TOP
    Copyright © 2018 www.massapi.com. All rights reserved.
    All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.