We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
下面getMyObject方法获取的是同样内容个对象,区别是一个用HashMap一个用TreeMap。但第二次序列化的时候将不会用serializeUsing中指定的类去序列化
public class Mock { @Test public void test() { Assert.assertEquals( JSON.toJSONString(getMyObject(new HashMap<String, Name>())), JSON.toJSONString(getMyObject(new TreeMap<String, Name>())) ); } private static MyObject getMyObject(Map<String, Name> names) { MyObject mapObj = new MyObject(); mapObj.setNames(names); Name name = new Name(); name.setFirst("foo"); name.setSecond("boo"); names.put("mock", name); return mapObj; } public static class NameMapCodec implements ObjectSerializer { @Override public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { JSONObject names = new JSONObject(); for(Map.Entry<String, Name> entry : ((Map<String, Name>)object).entrySet()) { Name name = entry.getValue(); names.put(entry.getKey(), name.getFirst() + ":" + name.getSecond()); } MapSerializer.instance.write(serializer, names, fieldName, JSONObject.class, features); } } public static class MyObject { @JSONField(serializeUsing = NameMapCodec.class) private Map<String, Name> names; public Map<String, Name> getNames() { return names; } public void setNames(Map<String, Name> names) { this.names = names; } } private static class Name { private String first; private String second; public String getFirst() { return first; } public void setFirst(String first) { this.first = first; } public String getSecond() { return second; } public void setSecond(String second) { this.second = second; } } }
貌似问题处在FieldSerializer中
Class<?> valueClass = propertyValue.getClass(); ObjectSerializer valueSerializer; if (valueClass == runtimeInfo.runtimeFieldClass) { valueSerializer = runtimeInfo.fieldSerializer; } else { valueSerializer = serializer.getObjectWriter(valueClass); }
runtimeInfo会缓存第一次序列化时候的类型即HashMap,第二次TreeMap将进入else中。
The text was updated successfully, but these errors were encountered:
什么版本?
Sorry, something went wrong.
1.2.23 1.2.22都有 应该其他版本也有 没试过
bug fixed for JSONField.serializeUsing. issue #989
a547dcc
问题重现并且解决,1.2.24版本将会带上,预计在春节前发布新版
bug fixed for JSONField.serializeUsing. issue alibaba#989
424b014
No branches or pull requests
下面getMyObject方法获取的是同样内容个对象,区别是一个用HashMap一个用TreeMap。但第二次序列化的时候将不会用serializeUsing中指定的类去序列化
貌似问题处在FieldSerializer中
runtimeInfo会缓存第一次序列化时候的类型即HashMap,第二次TreeMap将进入else中。
The text was updated successfully, but these errors were encountered: