Search in sources :

Example 1 with ExclusionStrategy

use of com.google.gson.ExclusionStrategy in project camel by apache.

the class GsonDataFormat method doStart.

@Override
protected void doStart() throws Exception {
    if (gson == null) {
        GsonBuilder builder = new GsonBuilder();
        if (exclusionStrategies != null && !exclusionStrategies.isEmpty()) {
            ExclusionStrategy[] strategies = exclusionStrategies.toArray(new ExclusionStrategy[exclusionStrategies.size()]);
            builder.setExclusionStrategies(strategies);
        }
        if (longSerializationPolicy != null) {
            builder.setLongSerializationPolicy(longSerializationPolicy);
        }
        if (fieldNamingPolicy != null) {
            builder.setFieldNamingPolicy(fieldNamingPolicy);
        }
        if (fieldNamingStrategy != null) {
            builder.setFieldNamingStrategy(fieldNamingStrategy);
        }
        if (serializeNulls) {
            builder.serializeNulls();
        }
        if (prettyPrint) {
            builder.setPrettyPrinting();
        }
        if (dateFormatPattern != null) {
            builder.setDateFormat(dateFormatPattern);
        }
        gson = builder.create();
    }
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) ExclusionStrategy(com.google.gson.ExclusionStrategy)

Example 2 with ExclusionStrategy

use of com.google.gson.ExclusionStrategy 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

ExclusionStrategy (com.google.gson.ExclusionStrategy)2 GsonBuilder (com.google.gson.GsonBuilder)2 Bitmap (android.graphics.Bitmap)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 FieldAttributes (com.google.gson.FieldAttributes)1 Gson (com.google.gson.Gson)1