List of usage examples for com.google.gson JsonSerializationContext serialize
public JsonElement serialize(Object src);
From source file:org.xacml4j.v30.marshal.json.RequestReferenceAdapter.java
License:Open Source License
@Override public JsonElement serialize(RequestReference src, Type typeOfSrc, JsonSerializationContext context) { JsonObject o = new JsonObject(); o.add(REFERENCE_ID_PROPERTY, context.serialize(src.getReferencedCategories())); return o;//ww w . j a va 2 s . com }
From source file:org.xacml4j.v30.marshal.json.ResponseContextAdapter.java
License:Open Source License
@Override public JsonElement serialize(ResponseContext src, Type typeOfSrc, JsonSerializationContext context) { JsonObject o = new JsonObject(); System.out.println("Response marsahall"); o.add(RESULT_PROPERTY, context.serialize(src.getResults())); return o;//from w ww. j a v a 2s . c om }
From source file:org.xacml4j.v30.marshal.json.ResultAdapter.java
License:Open Source License
@Override public JsonElement serialize(Result src, Type typeOfSrc, JsonSerializationContext context) { JsonObject o = new JsonObject(); o.addProperty(DECISION_PROPERTY, DECISION_VALUE_MAP.get(src.getDecision())); if (src.getStatus() != null) { o.add(STATUS_PROPERTY, context.serialize(src.getStatus())); }/* www . ja v a2 s . co m*/ Collection<Obligation> obligations = src.getObligations(); if (obligations != null && !obligations.isEmpty()) { o.add(OBLIGATIONS_PROPERTY, context.serialize(obligations, OBLIGATIONS_TYPE)); } Collection<Advice> associatedAdvice = src.getAssociatedAdvice(); if (associatedAdvice != null && !associatedAdvice.isEmpty()) { o.add(ASSOCIATED_ADVICE_PROPERTY, context.serialize(associatedAdvice, ADVICE_TYPE)); } Collection<Category> attributes = src.getIncludeInResultAttributes(); if (attributes != null && !attributes.isEmpty()) { o.add(ATTRIBUTES_PROPERTY, context.serialize(attributes)); } serializePolicyIdentifiers(src, context, o); return o; }
From source file:org.xacml4j.v30.marshal.json.ResultAdapter.java
License:Open Source License
private void serializePolicyIdentifiers(Result src, JsonSerializationContext context, JsonObject o) { Collection<CompositeDecisionRuleIDReference> policyIdentifiers = src.getPolicyIdentifiers(); if (policyIdentifiers != null && !policyIdentifiers.isEmpty()) { JsonObject policyIdentifiersJson = new JsonObject(); List<PolicyIDReference> policyIdReferences = Lists.newArrayList(); List<PolicySetIDReference> policySetIdReferences = Lists.newArrayList(); splitPolicyIdentifiers(policyIdentifiers, policyIdReferences, policySetIdReferences); if (!policyIdReferences.isEmpty()) { policyIdentifiersJson.add(POLICY_ID_REFERENCE_PROPERTY, context.serialize(policyIdReferences)); }/* w ww.j a va 2 s . com*/ if (!policySetIdReferences.isEmpty()) { policyIdentifiersJson.add(POLICY_SET_ID_REFERENCE_PROPERTY, context.serialize(policySetIdReferences)); } o.add(POLICY_IDENTIFIER_PROPERTY, policyIdentifiersJson); } }
From source file:org.xacml4j.v30.marshal.json.StatusAdapter.java
License:Open Source License
@Override public JsonElement serialize(Status src, Type typeOfSrc, JsonSerializationContext context) { JsonObject o = new JsonObject(); o.addProperty(STATUS_MESSAGE_PROPERTY, src.getMessage()); // TODO: serialize status detail o.add(STATUS_CODE_PROPERTY, context.serialize(src.getStatusCode())); return o;/*from w ww . j av a2 s . c o m*/ }
From source file:org.xacml4j.v30.marshal.json.StatusCodeAdapter.java
License:Open Source License
@Override public JsonElement serialize(StatusCode src, Type typeOfSrc, JsonSerializationContext context) { JsonObject o = new JsonObject(); o.addProperty(VALUE_PROPERTY, src.getValue().toString()); if (src.getMinorStatus() != null) { o.add(STATUS_CODE_PROPERTY, context.serialize(src.getMinorStatus())); }// w w w . j a va 2 s. com return o; }
From source file:org.xjava.gsonrpc.gson.JsonRPCErrorResponseSerializer.java
License:Open Source License
@Override public JsonElement serialize(JsonRPCErrorResponse errorResponse, Type type, JsonSerializationContext ctx) { JsonObject json = new JsonObject(); json.addProperty("jsonrpc", errorResponse.getVersion()); json.addProperty("id", errorResponse.getId()); JsonObject error = ctx.serialize(errorResponse.getError()).getAsJsonObject(); if (errorResponse.getDataJson() != null && !errorResponse.getDataJson().isJsonNull()) error.add("data", errorResponse.getDataJson()); json.add("error", error); return json;// w ww . j a v a2s.c o m }
From source file:pl.llp.aircasting.api.gson.NoteAdapter.java
License:Open Source License
@Override public JsonElement serialize(Note note, Type type, JsonSerializationContext context) { JsonObject object = new JsonObject(); object.addProperty("number", note.getNumber()); object.addProperty("latitude", note.getLatitude()); object.addProperty("longitude", note.getLongitude()); object.add("date", context.serialize(note.getDate())); object.addProperty("text", note.getText()); return object; }
From source file:rest.ws.gson.serializer.MessageSerializer.java
@Override public JsonElement serialize(Message message, Type type, JsonSerializationContext jsc) { final JsonObject jsonObject = new JsonObject(); jsonObject.addProperty(ACTION, message.getActionName()); jsonObject.addProperty(DATA_TYPE, message.getDataType()); if (message.getDataContainer() != null) jsonObject.add(DATA_CONTAINER, jsc.serialize(message.getDataContainer())); if (message.getLogList() != null) jsonObject.add(LOG_LIST, jsc.serialize(message.getLogList())); if (message.getLinks() != null) jsonObject.add(LINKS, serializeLinkList(message.getLinks(), jsc)); if (message.getData() != null) jsonObject.add(DATA, jsc.serialize(message.getData())); return jsonObject; }
From source file:ro.agitman.customserializer.utils.CustomSerializer.java
@Override public JsonElement serialize(AbstractSerializer t, Type type, JsonSerializationContext jsc) { JsonObject object = new JsonObject(); String clazz = t.getClass().getName(); object.addProperty(JsonName.CLASS_NAME, clazz); Map<String, JsonElement> map = new HashMap<>(); Class aClass = t.getClass();/*ww w.j av a2 s . c o m*/ Field[] fields = aClass.getDeclaredFields(); try { for (Field field : fields) { field.setAccessible(true); map.put(field.getName(), jsc.serialize(field.get(t))); } } catch (IllegalArgumentException | IllegalAccessException iae) { iae.printStackTrace(); } object.add(JsonName.PROPS, jsc.serialize(map)); return object; }