I defined a simple POJO:
public class ProtoVO {
private int id;
private String name;
private Date timestamp;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
@Override
public String toString() {
return "ProtoVO [id=" + id + ", name=" + name + ", timestamp="
+ timestamp + "]";
}
}
and try to run a simple sample:
Schema<ProtoVO> schema = RuntimeSchema.getSchema(ProtoVO.class);
// Schema<ProtoVO> schema = new ProtoVOSchema();
LinkedBuffer buffer = LinkedBuffer.allocate(1024);
ProtoVO vo = new ProtoVO();
vo.setId(11);
vo.setName("darren");
vo.setTimestamp(new Date());
byte[] bytes = ProtostuffIOUtil.toByteArray(vo, schema,
buffer);
ProtoVO v = new ProtoVO();
ProtostuffIOUtil.mergeFrom(bytes, v, schema);
System.out.println(v);
But I got exception from the 1st line:
Exception in thread "main" java.lang.RuntimeException: All fields are
either transient/static. Note that Map fields are excluded. Two
dimensional array fields are excluded. Collection fields whose
generic type is a collection or another generic type, are excluded.
at
com.dyuproject.protostuff.runtime.RuntimeSchema.createFrom(RuntimeSchema.java:
138)
at
com.dyuproject.protostuff.runtime.RuntimeSchema.createFrom(RuntimeSchema.java:
85)
at com.dyuproject.protostuff.runtime.RuntimeSchema
$Lazy.getSchema(RuntimeSchema.java:283)
at
com.dyuproject.protostuff.runtime.RuntimeSchema.getSchema(RuntimeSchema.java:
77)
at com.dyuproject.protostuff.runtime.RuntimeFieldFactory
$14$1.<init>(RuntimeFieldFactory.java:1119)
at com.dyuproject.protostuff.runtime.RuntimeFieldFactory
$14.create(RuntimeFieldFactory.java:1117)
at
com.dyuproject.protostuff.runtime.RuntimeSchema.createFrom(RuntimeSchema.java:
127)
at
com.dyuproject.protostuff.runtime.RuntimeSchema.createFrom(RuntimeSchema.java:
85)
at com.dyuproject.protostuff.runtime.RuntimeSchema
$Lazy.getSchema(RuntimeSchema.java:283)
at
com.dyuproject.protostuff.runtime.RuntimeSchema.getSchema(RuntimeSchema.java:
77)
at
cn.spring21.sandbox.protostuff.ProtostuffMarshaller.main(ProtostuffMarshaller.java:
16)
Did I miss sth?