![JAR search and dependency download from the Maven repository](/logo.png)
com.alibaba.fastjson.serializer.GuavaCodec Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fastjson-to-easyjson Show documentation
Show all versions of fastjson-to-easyjson Show documentation
Adapter alibaba fastjson to other json libraries. the fastjson version: 1.2.58
package com.alibaba.fastjson.serializer;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* Created by wenshao on 15/01/2017.
*/
public class GuavaCodec implements ObjectSerializer, ObjectDeserializer {
public static GuavaCodec instance = new GuavaCodec();
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
if (object instanceof Multimap) {
Multimap multimap = (Multimap) object;
serializer.write(multimap.asMap());
}
}
public T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
if (type == ArrayListMultimap.class) {
ArrayListMultimap multimap = ArrayListMultimap.create();
JSONObject object = parser.parseObject();
for (Map.Entry entry : object.entrySet()) {
Object value = entry.getValue();
if (value instanceof Collection) {
multimap.putAll(entry.getKey(), (List) value);
} else {
multimap.put(entry.getKey(), value);
}
}
return (T) multimap;
}
return null;
}
public int getFastMatchToken() {
return 0;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy