use of com.google.gson.FieldAttributes 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;
}
use of com.google.gson.FieldAttributes in project acs-aem-commons by Adobe-Consulting-Services.
the class ControlledProcessManagerServlet method doGet.
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
String action = request.getRequestPathInfo().getSelectorString();
Object result = null;
try {
switch(action) {
case "start":
result = doStartProcess(request);
break;
case "list":
result = doProcessList();
break;
case "status":
result = doProcessStatusCheck(request);
break;
case "halt":
result = doHaltProcess(request);
break;
case "haltAll":
case "halt.all":
case "halt-all":
result = doHaltAllProcesses(request);
break;
case "purge":
result = doPurgeCompleted(request);
break;
default:
throw new IllegalArgumentException("Action not understood.");
}
} catch (Exception ex) {
result = "Exception occurred " + ex.getMessage();
LOG.error(ex.getMessage() + " -- End of line.", ex);
}
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.addSerializationExclusionStrategy(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes fa) {
return (fa.hasModifier(Modifier.TRANSIENT) || fa.hasModifier(Modifier.VOLATILE));
}
@Override
public boolean shouldSkipClass(Class<?> type) {
return !type.isArray() && !type.isPrimitive() && type.getPackage().getName().startsWith("java.io");
}
});
gsonBuilder.disableInnerClassSerialization();
Gson gson = gsonBuilder.create();
gson.toJson(result, response.getWriter());
}
use of com.google.gson.FieldAttributes in project netxms by netxms.
the class JsonTools method jsonFromObject.
/**
* Create JSON representation for given object
*
* @param object object to serialize
* @return JSON code
*/
public static String jsonFromObject(Object object, Set<String> fields) {
if ((object instanceof JsonObject) || (object instanceof JsonArray) || (object instanceof JSONObject) || (object instanceof JSONArray))
return JsonFilter.createFilter(object, fields).filter().toString();
if (object instanceof ResponseContainer)
return ((ResponseContainer) object).toJson(fields);
GsonBuilder builder = new GsonBuilder();
// FIXME: remove for production
builder.setPrettyPrinting();
builder.registerTypeAdapter(Date.class, new DateAdapter());
builder.registerTypeAdapter(InetAddress.class, new InetAddressAdapter());
builder.registerTypeAdapter(InetAddressEx.class, new InetAddressExAdapter());
builder.registerTypeAdapter(MacAddress.class, new MacAddressAdapter());
builder.setExclusionStrategies(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getAnnotation(Internal.class) != null;
}
@Override
public boolean shouldSkipClass(Class<?> c) {
return c.isAnnotationPresent(Internal.class);
}
});
if ((fields != null) && !fields.isEmpty()) {
return JsonFilter.createFilter(builder.create().toJsonTree(object), fields).filter().toString();
}
return builder.create().toJson(object);
}
use of com.google.gson.FieldAttributes in project cuba by cuba-platform.
the class CubaJavaScriptComponent method createSharedGsonBuilder.
protected static GsonBuilder createSharedGsonBuilder() {
GsonBuilder builder = new GsonBuilder();
builder.setExclusionStrategies(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
Expose expose = f.getAnnotation(Expose.class);
return expose != null && !expose.serialize();
}
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}
});
setDefaultProperties(builder);
return builder;
}
Aggregations