
com.fimet.json.JExeAdapterFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fimet-exe Show documentation
Show all versions of fimet-exe Show documentation
Execution implementarion of usecases and stress test for ISO8583
The newest version!
package com.fimet.json;
import com.fimet.parser.IMessage;
import com.fimet.simulator.ISimulator;
import com.fimet.usecase.IUseCase;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.Map;
public class JExeAdapterFactory implements TypeAdapterFactory {
public static final JExeAdapterFactory INSTANCE = new JExeAdapterFactory();
public static final Gson GSON = new GsonBuilder()
.disableHtmlEscaping()
.registerTypeAdapterFactory(JExeAdapterFactory.INSTANCE)
.create();
public static final Gson GSON_PRETTY = new GsonBuilder()
.setPrettyPrinting()
.disableHtmlEscaping()
.registerTypeAdapterFactory(JExeAdapterFactory.INSTANCE)
.create();
private static final Type iSimulatorType = new TypeToken() {}.getType();
private static final Type iMessageType = new TypeToken() {}.getType();
private static final Type iUseCaseType = new TypeToken() {}.getType();
private static final Type jUseCaseMapType = new TypeToken() {}.getType();
private static final Type jUseCaseJMsgType = new TypeToken() {}.getType();
private static final Type jStressFileBuilderType = new TypeToken() {}.getType();
private static final Type messageMapType = new TypeToken() {}.getType();
private static final Type messageTreeType = new TypeToken() {}.getType();
@SuppressWarnings("unchecked")
public TypeAdapter create(Gson gson, TypeToken type) {
if (type.getType().equals(iUseCaseType)) {
return (TypeAdapter)new IUseCaseAdapter((TypeAdapter)gson.getDelegateAdapter(this, type));
} else if (type.getType().equals(jUseCaseMapType)) {
return (TypeAdapter)new JUseCaseAdapter((TypeAdapter)gson.getDelegateAdapter(this, type));
} else if (type.getType().equals(jUseCaseJMsgType)) {
return (TypeAdapter)new JUseCaseJMsgAdapter((TypeAdapter)gson.getDelegateAdapter(this, type));
} else if (type.getType().equals(messageMapType)) {
return (TypeAdapter)new JMessageMapAdapter();
} else if (type.getType().equals(messageTreeType)) {
return (TypeAdapter)new JMessageTreeAdapter();
} else if (type.getType().equals(iMessageType)) {
return (TypeAdapter)new IMessageAdapter();
} else if (type.getType().equals(iSimulatorType)) {
return (TypeAdapter)new ISimulatorAdapter((TypeAdapter)gson.getDelegateAdapter(this, type));
} else if (type.getType().equals(jStressFileBuilderType)) {
return (TypeAdapter)new JStressFileBuilderAdapter((TypeAdapter)gson.getDelegateAdapter(this, type));
} else {
return gson.getDelegateAdapter(this, type);
}
}
public static T fromJson(String json, Class clazz) {
return GSON.fromJson(json, clazz);
}
public static T fromJson(String json, Type typeOfT) {
return GSON.fromJson(json, typeOfT);
}
public static String toJson(Object object) {
return GSON.toJson(object);
}
public static String toPrettyJson(Object object) {
return GSON_PRETTY.toJson(object);
}
public static Map parseJsonAsMap(String json){
Type type = new TypeToken
© 2015 - 2025 Weber Informatics LLC | Privacy Policy