use of com.google.gson.GsonBuilder in project tika by apache.
the class JsonMetadataBase method defaultInit.
static Gson defaultInit() {
GsonBuilder builder = new GsonBuilder();
builder.registerTypeHierarchyAdapter(Metadata.class, new JsonMetadataSerializer());
builder.registerTypeHierarchyAdapter(Metadata.class, new JsonMetadataDeserializer());
return builder.create();
}
use of com.google.gson.GsonBuilder in project GeoGig by boundlessgeo.
the class Mapping method fromString.
/**
* Creates a Mapping object from its JSON representation
*
* @param s the JSON representation
* @return the created mapping
*/
public static Mapping fromString(String s) {
GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
Gson gson = gsonBuilder.create();
Mapping mapping;
try {
mapping = gson.fromJson(s, Mapping.class);
} catch (JsonSyntaxException e) {
throw new IllegalArgumentException("Error parsing mapping definition: " + e.getMessage(), e);
}
return mapping;
}
use of com.google.gson.GsonBuilder in project Gargoyle by callakrsos.
the class ValueUtil method toStringPrettyFormat.
/**
* @작성자 : KYJ
* @작성일 : 2017. 4. 5.
* @param json
* @return
*/
public static String toStringPrettyFormat(String json) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(json);
return gson.toJson(je);
}
use of com.google.gson.GsonBuilder in project SimpleAsteroids by ljialin.
the class BanditEA method runTrials.
public static StatSummary runTrials(int nBandits, int nTrials) throws Exception {
StatSummary ss = new StatSummary();
ArrayList<int[][]> examples = new ArrayList<>();
// System.out.println(examples);
rankCorrelation = new RankCorrelation();
for (int i = 0; i < nTrials; i++) {
BanditEA ea = new BanditEA(nBandits);
ea.evaluator = new ShortestPathTest();
ElapsedTimer t = new ElapsedTimer();
ea.run(nEvals);
System.out.println(t);
if (ea.success) {
// ss.add(ea.trialsSoFar);
}
ss.add(ea.evaluate(ea.genome));
System.out.println("Checking fitness: " + ea.evaluate(ea.genome));
examples.add(toSquareArray(ea.genome.toArray()));
System.out.println("Rank correlation check:");
rankCorrelation.rankCorrelation();
}
System.out.println("Created mazes");
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String out = gson.toJson(examples);
System.out.println("Created JSON String");
// System.out.println(out);
String outputFile = "data/mazes.json";
PrintWriter writer = new PrintWriter(outputFile);
writer.print(out);
writer.close();
System.out.println("Wrote file with " + examples.size() + " examples");
return ss;
}
use of com.google.gson.GsonBuilder in project MVCHelper by LuckyJayce.
the class ABSTestCaseFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
this.inflater = inflater;
View view = inflater.inflate(R.layout.testcase, container, false);
taskHelper = new TaskHelper<>();
GsonBuilder builder = new GsonBuilder();
// 格式化输出
builder.setPrettyPrinting();
// builder.serializeNulls();
builder.addSerializationExclusionStrategy(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
// true; //按注解排除
return false;
}
@Override
public boolean shouldSkipClass(Class<?> clazz) {
// 直接排除某个类 ,return true为排除
return clazz == Gson.class || clazz == Bitmap.class;
}
}).create();
gson = builder.create();
recyclerView = (RecyclerView) view.findViewById(R.id.testcase2_recyclerView);
paramsRecyclerView = (LinearLayout) view.findViewById(R.id.testcase2_params_recyclerView);
resultTextView = (TextView) view.findViewById(R.id.testcase2_result_textView);
runButton = (Button) view.findViewById(R.id.testcase2_run_button);
resetButton = (Button) view.findViewById(R.id.testcase2_reset_button);
itemRunButton = view.findViewById(R.id.testcase2_run2_button);
resultStateTextView = (TextView) view.findViewById(R.id.testcase2_resultState_textView);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(tasksAdapter = new TasksAdapter());
// recyclerView.addItemDecoration(new DividerItemDecoration(getContext()));
//
// // paramsRecyclerView.setLayoutManager(new
// // LinearLayoutManager(getContext()));
// // paramsRecyclerView.addItemDecoration(new
// // DividerItemDecoration(getContext()));
// // paramsRecyclerView.setAdapter(paramsAdapter = new ParamsAdapter());
datas = getTestCaseDatas();
resetButton.setOnClickListener(onClickListener);
runButton.setOnClickListener(onClickListener);
itemRunButton.setOnClickListener(onClickListener);
tasksAdapter.setOnItemClickListener(onItemClickListener);
resultTextView.setOnClickListener(onClickListener);
updateRight();
return view;
}
Aggregations