Search in sources :

Example 71 with GsonBuilder

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();
}
Also used : GsonBuilder(com.google.gson.GsonBuilder)

Example 72 with GsonBuilder

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;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson)

Example 73 with GsonBuilder

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);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) JsonElement(com.google.gson.JsonElement) Gson(com.google.gson.Gson) JsonParser(com.google.gson.JsonParser)

Example 74 with GsonBuilder

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;
}
Also used : StatSummary(utilities.StatSummary) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) RankCorrelation(ntuple.RankCorrelation) ShortestPathTest(evomaze.ShortestPathTest) Gson(com.google.gson.Gson) ElapsedTimer(utilities.ElapsedTimer) PrintWriter(java.io.PrintWriter)

Example 75 with GsonBuilder

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;
}
Also used : Bitmap(android.graphics.Bitmap) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) ExclusionStrategy(com.google.gson.ExclusionStrategy) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) FieldAttributes(com.google.gson.FieldAttributes)

Aggregations

GsonBuilder (com.google.gson.GsonBuilder)1067 Gson (com.google.gson.Gson)803 IOException (java.io.IOException)185 Test (org.junit.Test)141 ArrayList (java.util.ArrayList)101 JsonObject (com.google.gson.JsonObject)90 File (java.io.File)80 JsonElement (com.google.gson.JsonElement)78 HashMap (java.util.HashMap)67 List (java.util.List)62 Map (java.util.Map)59 Retrofit (retrofit2.Retrofit)56 Type (java.lang.reflect.Type)52 FileNotFoundException (java.io.FileNotFoundException)42 TypeToken (com.google.gson.reflect.TypeToken)40 ResponseBody (okhttp3.ResponseBody)39 FileOutputStream (java.io.FileOutputStream)38 Call (retrofit2.Call)38 JsonSyntaxException (com.google.gson.JsonSyntaxException)37 JsonParser (com.google.gson.JsonParser)36