List of usage examples for com.google.gson JsonSerializationContext serialize
public JsonElement serialize(Object src, Type typeOfSrc);
From source file:io.ucoin.ucoinj.core.client.model.bma.gson.JoinerTypeAdapter.java
License:Open Source License
@Override public JsonElement serialize(BlockchainBlock.Joiner member, Type type, JsonSerializationContext context) { String result = new StringBuilder().append(member.getPubkey()).append(":").append(member.getSignature()) .append(":").append(member.getNumber()).append(":").append(member.getHash()).append(":") .append(member.getTimestamp()).append(":").append(member.getUid()).toString(); return context.serialize(result.toString(), String.class); }
From source file:main.java.miro.validator.export.json.CertificateObjectJsonSerializer.java
License:Open Source License
public JsonElement serialize(CertificateObject cw, Type typeOfSrc, JsonSerializationContext context) { JsonObject cwJson = new JsonObject(); cwJson.add("filename", new JsonPrimitive(cw.getFilename())); cwJson.add("subject", new JsonPrimitive(cw.getSubject().toString())); cwJson.add("serial_nr", new JsonPrimitive(cw.getSerialNr().toString())); cwJson.add("issuer", new JsonPrimitive(cw.getIssuer().toString())); cwJson.add("subject_key_identifier", new JsonPrimitive(ResourceCertificateTreeValidator.bytesToHex(cw.getSubjectKeyIdentifier()))); cwJson.add("public_key", new JsonPrimitive((cw.getPublicKey().toString()))); cwJson.add("isEE", new JsonPrimitive(cw.getIsEE())); cwJson.add("isCA", new JsonPrimitive(cw.getIsCA())); cwJson.add("isRoot", new JsonPrimitive(cw.getIsRoot())); cwJson.add("validity_period", new JsonPrimitive(cw.getValidityPeriod().toString())); cwJson.add("validation_result", context.serialize(cw.getValidationResults(), ValidationResults.class)); cwJson.add("resources", context.serialize(cw.getResources(), IpResourceSet.class)); if (cw.getAki() != null) { cwJson.add("authority_key_identifier", new JsonPrimitive(ResourceCertificateTreeValidator.bytesToHex(cw.getAki()))); }//from ww w . j av a2 s. c o m if (cw.getManifest() != null) { cwJson.add("manifest", context.serialize(cw.getManifest(), ManifestObject.class)); } if (cw.getX509Crl() != null) { cwJson.add("crl", context.serialize(cw.getCrl(), CRLObject.class)); } if (includeSubtree) { JsonArray children_json = new JsonArray(); JsonObject childJson; String type; if (cw.getChildren() != null) { for (ResourceHoldingObject kid : cw.getChildren()) { childJson = new JsonObject(); if (kid instanceof CertificateObject) { type = "cer"; } else { type = "roa"; } childJson.add("type", new JsonPrimitive(type)); childJson.add("child", context.serialize(kid, ResourceHoldingObject.class)); children_json.add(childJson); } } cwJson.add("children", children_json); } return cwJson; }
From source file:main.java.miro.validator.export.json.CRLSerializer.java
License:Open Source License
public JsonElement serialize(CRLObject src, Type typeOfSrc, JsonSerializationContext context) { X509Crl crl = src.getCrl();/*from w w w . ja v a 2 s . co m*/ JsonObject crl_json = new JsonObject(); crl_json.add("filename", new JsonPrimitive(src.getFilename())); JsonArray revoked_certs_json = new JsonArray(); JsonObject revoked_cert_json; Set<Entry> revoked_certs = crl.getRevokedCertificates(); for (Entry e : revoked_certs) { revoked_cert_json = new JsonObject(); revoked_cert_json.add("serial_nr", new JsonPrimitive(e.getSerialNumber().toString())); revoked_cert_json.add("revocation_time", new JsonPrimitive(e.getRevocationDateTime().toString())); revoked_certs_json.add(revoked_cert_json); } crl_json.add("validation_result", context.serialize(src.getValidationResults(), ValidationResults.class)); crl_json.add("revoked_certificates", revoked_certs_json); return crl_json; }
From source file:main.java.miro.validator.export.json.ResourceCertificateTreeSerializer.java
License:Open Source License
public JsonElement serialize(ResourceCertificateTree src, Type typeOfSrc, JsonSerializationContext context) { JsonObject treeJson = new JsonObject(); treeJson.add("name", new JsonPrimitive(src.getName())); treeJson.add("date", new JsonPrimitive(src.getTimeStamp().toString())); treeJson.add("trustAnchor", context.serialize(src.getTrustAnchor(), CertificateObject.class)); return treeJson; }
From source file:main.java.miro.validator.export.json.ResourceHoldingObjectSerializer.java
License:Open Source License
public JsonElement serialize(ResourceHoldingObject src, Type typeOfSrc, JsonSerializationContext context) { if (src instanceof CertificateObject) { return context.serialize(src, CertificateObject.class); }//from w ww. j ava 2 s .c o m if (src instanceof RoaObject) { return context.serialize(src, RoaObject.class); } return null; }
From source file:main.java.miro.validator.export.json.RoaSerializer.java
License:Open Source License
public JsonElement serialize(RoaObject src, Type typeOfSrc, JsonSerializationContext context) { JsonObject roa_json = new JsonObject(); RoaCms roa = src.getRoa();/*from w w w.ja v a 2 s. c o m*/ roa_json.add("filename", new JsonPrimitive(src.getFilename())); roa_json.add("asn", new JsonPrimitive(roa.getAsn().toString())); roa_json.add("validity_period", new JsonPrimitive(roa.getValidityPeriod().toString())); roa_json.add("signing_time", new JsonPrimitive(roa.getSigningTime().toString())); JsonArray prefixes_json = new JsonArray(); JsonObject roa_prefix_json; for (RoaPrefix prefix : roa.getPrefixes()) { roa_prefix_json = new JsonObject(); roa_prefix_json.add("prefix", new JsonPrimitive(prefix.getPrefix().toString())); roa_prefix_json.add("maxLength", new JsonPrimitive(prefix.getEffectiveMaximumLength())); prefixes_json.add(roa_prefix_json); } roa_json.add("prefixes", prefixes_json); roa_json.add("validation_result", context.serialize(src.getValidationResults(), ValidationResults.class)); // roa_json.add("eeCert", context.serialize(src.getEeCert(), CertificateObject.class)); return roa_json; }
From source file:main.java.miro.validator.export.json.ValidationResultsSerializer.java
License:Open Source License
public JsonElement serialize(ValidationResults src, Type typeOfSrc, JsonSerializationContext context) { JsonObject validation_results_json = new JsonObject(); JsonArray passed_results_json = new JsonArray(); JsonArray error_results_json = new JsonArray(); JsonArray warning_results_json = new JsonArray(); ArrayList<ValidationCheck> passed_checks = src.getValidationResults().get(ValidationStatus.PASSED); ArrayList<ValidationCheck> error_checks = src.getValidationResults().get(ValidationStatus.ERROR); ArrayList<ValidationCheck> warning_checks = src.getValidationResults().get(ValidationStatus.WARNING); // if(passed_checks != null){ // for(ValidationCheck check : passed_checks){ // passed_results_json.add(context.serialize(check,ValidationCheck.class)); // }/*from w w w . j av a 2 s . c o m*/ // validation_results_json.add("passed", passed_results_json); // } validation_results_json.add("isValid", new JsonPrimitive(error_checks.isEmpty())); if (error_checks != null) { for (ValidationCheck check : error_checks) { error_results_json.add(context.serialize(check, ValidationCheck.class)); } validation_results_json.add("error", error_results_json); } if (warning_checks != null) { for (ValidationCheck check : warning_checks) { warning_results_json.add(context.serialize(check, ValidationCheck.class)); } validation_results_json.add("warning", warning_results_json); } return validation_results_json; }
From source file:me.cybermaxke.elementarrows.forge.json.JsonRecipe.java
License:Open Source License
@Override public JsonElement serialize(Recipe recipe, Type type, JsonSerializationContext ctx) { JsonObject json = new JsonObject(); if (recipe instanceof RecipeShaped) { RecipeShaped recipe0 = (RecipeShaped) recipe; JsonObject ingredients = new JsonObject(); for (Entry<Character, ItemStack> entry : recipe0.getIngredients().entrySet()) { ingredients.add(entry.getKey() + "", ctx.serialize(entry.getValue(), ItemStack.class)); }//from w ww . j a v a2s . c om json.add("result", ctx.serialize(recipe0.getResult(), ItemStack.class)); json.add("shape", ctx.serialize(recipe0.getShape(), String[].class)); json.add("ingredients", ingredients); } else if (recipe instanceof RecipeShapeless) { RecipeShapeless recipe0 = (RecipeShapeless) recipe; JsonArray ingredients = new JsonArray(); for (ItemStack itemStack : recipe0.getIngredients()) { ingredients.add(ctx.serialize(itemStack, ItemStack.class)); } json.add("result", ctx.serialize(recipe0.getResult(), ItemStack.class)); json.add("ingredients", ingredients); } else { throw new IllegalArgumentException("Unsupported recipe type! (" + recipe.getClass().getName() + ")"); } return json; }
From source file:net.simonvt.cathode.jobqueue.JobSerializer.java
License:Apache License
@Override public JsonElement serialize(Job src, Type typeOfSrc, JsonSerializationContext context) { final JsonObject member = new JsonObject(); member.addProperty("type", src.getClass().getName()); member.add("data", context.serialize(src, src.getClass())); return member; }
From source file:net.uiqui.couchdb.json.impl.SelectorSerializer.java
License:Apache License
private JsonElement serialize(final Condition condition, final Type typeOfSrc, final JsonSerializationContext context) { final JsonObject jsonObject = new JsonObject(); jsonObject.add(condition.field(), context.serialize(condition.operator(), typeOfSrc)); return jsonObject; }