0
我如何序列化对象喜欢用Protostuff下面的例子:Protostuff序列化对象地图一样<字符串,地图<String,字符串>>
Map<String, Map<String, String>>
我知道,我必须使用MapSchema,但我不知道我需要用这个对象来做什么。
我如何序列化对象喜欢用Protostuff下面的例子:Protostuff序列化对象地图一样<字符串,地图<String,字符串>>
Map<String, Map<String, String>>
我知道,我必须使用MapSchema,但我不知道我需要用这个对象来做什么。
类来序列外地图:
public class OuterMapSchema extends MapSchema<String, Map<String, String>> {
InnerMapSchema INNER_MAP_SCHEMA = new InnerMapSchema();
public OuterMapSchema() {
super(MessageFactories.HashMap);
}
@Override
protected String readKeyFrom(Input input, MapWrapper<String, Map<String, String>> wrapper) throws IOException {
return input.readString();
}
@Override
protected void putValueFrom(Input input, MapWrapper<String, Map<String, String>> wrapper, String key) throws IOException {
wrapper.put(key, input.mergeObject(null, INNER_MAP_SCHEMA));
}
@Override
protected void writeKeyTo(Output output, int fieldNumber, String value, boolean repeated) throws IOException {
output.writeString(fieldNumber, value, repeated);
}
@Override
protected void writeValueTo(Output output, int fieldNumber, Map<String, String> value, boolean repeated) throws IOException {
output.writeObject(fieldNumber, value, INNER_MAP_SCHEMA, repeated);
}
@Override
protected void transferKey(Pipe pipe, Input input, Output output, int number, boolean repeated) throws IOException {
}
@Override
protected void transferValue(Pipe pipe, Input input, Output output, int number, boolean repeated) throws IOException {
}
}
类来序列内地图:
public class InnerMapSchema extends MapSchema<String, String> {
public InnerMapSchema() {
super(MessageFactories.HashMap);
}
@Override
protected String readKeyFrom(Input input, MapWrapper<String, String> wrapper) throws IOException {
return input.readString();
}
@Override
protected void putValueFrom(Input input, MapWrapper<String, String> wrapper, String key) throws IOException {
wrapper.put(key, input.readString());
}
@Override
protected void writeKeyTo(Output output, int fieldNumber, String value, boolean repeated) throws IOException {
output.writeString(fieldNumber, value, repeated);
}
@Override
protected void writeValueTo(Output output, int fieldNumber, String value, boolean repeated) throws IOException {
output.writeString(fieldNumber, value, repeated);
}
@Override
protected void transferKey(Pipe pipe, Input input, Output output, int number, boolean repeated) throws IOException {
}
@Override
protected void transferValue(Pipe pipe, Input input, Output output, int number, boolean repeated) throws IOException {
}
}