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();
}
}
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;
}
Aggregations