调整Convert部分内部接口

This commit is contained in:
Redkale
2018-11-27 14:10:58 +08:00
parent 9e553aeff6
commit 47dab88d72
28 changed files with 353 additions and 132 deletions

View File

@@ -21,13 +21,14 @@ import org.redkale.util.*;
*/
public class BsonTestMain {
public static void main(String[] args) throws Exception {
public static void main(String[] args) throws Throwable {
Serializable[] sers = new Serializable[]{"aaa", 4};
final BsonConvert convert = BsonFactory.root().getConvert();
byte[] bytes = convert.convertTo(sers);
Utility.println("---", bytes);
Serializable[] a = convert.convertFrom(Serializable[].class, bytes);
System.out.println(Arrays.toString(a));
Two.main(args);
main2(args);
main3(args);
main4(args);

View File

@@ -0,0 +1,63 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.redkale.test.convert;
import org.redkale.convert.json.JsonConvert;
/**
*
* @author zhangjx
*/
public class One {
protected String key;
protected int code;
protected byte[] bytes = new byte[]{3, 4, 5};
protected int[] ints = new int[]{3000, 4000, 5000};
public One(int code) {
this.code = code;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public byte[] getBytes() {
return bytes;
}
public void setBytes(byte[] bytes) {
this.bytes = bytes;
}
public int[] getInts() {
return ints;
}
public void setInts(int[] ints) {
this.ints = ints;
}
public String toString() {
return JsonConvert.root().convertTo(this);
}
}

View File

@@ -0,0 +1,96 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.redkale.test.convert;
import java.util.*;
import org.redkale.convert.bson.BsonFactory;
/**
*
* @author zhangjx
*/
public class Two extends One {
public Two() {
super(90100119);
}
protected List<String> list;
protected Map<String, String> stringMap;
protected List<ConvertRecord> records;
protected Map<String, ConvertRecord> recordMap;
public Map<String, String> getStringMap() {
return stringMap;
}
public void setStringMap(Map<String, String> stringMap) {
this.stringMap = stringMap;
}
String ip;
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public List<String> getList() {
return list;
}
public void setList(List<String> list) {
this.list = list;
}
public List<ConvertRecord> getRecords() {
return records;
}
public void setRecords(List<ConvertRecord> records) {
this.records = records;
}
public Map<String, ConvertRecord> getRecordMap() {
return recordMap;
}
public void setRecordMap(Map<String, ConvertRecord> recordMap) {
this.recordMap = recordMap;
}
public static void main(String[] args) throws Throwable {
Two two = new Two();
two.setKey("key111");
two.setCode(12345);
List<String> list = new ArrayList<>();
list.add("haha");
two.setList(list);
Map<String, String> map = new HashMap<>();
map.put("222", "333");
two.setStringMap(map);
List<ConvertRecord> records = new ArrayList<>();
records.add(ConvertRecord.createDefault());
two.setRecords(records);
Map<String, ConvertRecord> rmap = new HashMap<>();
rmap.put("222", ConvertRecord.createDefault());
two.setRecordMap(rmap);
byte[] bs = BsonFactory.root().getConvert().convertTo(two);
One one =BsonFactory.root().getConvert().convertFrom(One.class, bs);
System.out.println(one);
}
}