List of usage examples for com.google.gson JsonPrimitive JsonPrimitive
public JsonPrimitive(Character c)
From source file:com.exalttech.trex.ui.views.streams.binders.BuilderDataBinding.java
License:Apache License
private JsonObject buildProtoField(String id, String val) { JsonObject field = new JsonObject(); field.add("id", new JsonPrimitive(id)); field.add("value", new JsonPrimitive(val)); return field; }
From source file:com.example.app.support.ui.vtcrop.VTCropPictureEditorConfig.java
License:Open Source License
/** * To json.//w w w. j av a 2s. c o m * * @return the string */ public String toJson() { Gson gson = new Gson(); JsonObject json = new JsonObject(); if (getImageSelector() != null) json.add("image_selector", new JsonPrimitive(getImageSelector())); if (getAcceptUndefinedImageTarget() != null) json.add("accept_undefined_image_target", new JsonPrimitive(getAcceptUndefinedImageTarget())); if (getConstrainAspectRatio() != null) json.add("constrain_aspectratio", new JsonPrimitive(getConstrainAspectRatio())); if (getMinWidth() != null) json.add("min_width", new JsonPrimitive(getMinWidth())); if (getMinHeight() != null) json.add("min_height", new JsonPrimitive(getMinHeight())); if (getMaxWidth() != null) json.add("max_width", new JsonPrimitive(getMaxWidth())); if (getMaxHeight() != null) json.add("max_height", new JsonPrimitive(getMaxHeight())); if (getCropWidth() != null) json.add("crop_width", new JsonPrimitive(getCropWidth())); if (getCropHeight() != null) json.add("crop_height", new JsonPrimitive(getCropHeight())); if (getImageBackgroundStr() != null) json.add("image_background_str", new JsonPrimitive(getImageBackgroundStr())); if (getImageType() != null) json.add("image_type", new JsonPrimitive(getImageType())); if (getEncoderOptions() != null) json.add("encoder_options", new JsonPrimitive(getEncoderOptions())); if (getImageScales() != null) { JsonArray imageScales = new JsonArray(); for (ImageScaleOption imageScale : getImageScales()) { imageScales.add(gson.toJsonTree(imageScale)); } json.add("image_scales", imageScales); } return gson.toJson(json); }
From source file:com.exorath.commons.ItemStackSerialize.java
License:Apache License
public static JsonObject fromItemStack(ItemStack is) { JsonObject itemObject = new JsonObject(); itemObject.addProperty("material", is.getType().name()); itemObject.addProperty("amount", is.getAmount()); itemObject.addProperty("durability", is.getDurability()); if (is.getItemMeta().hasDisplayName()) itemObject.addProperty("displayName", is.getItemMeta().getDisplayName()); if (is.getItemMeta().hasLore()) { JsonArray lore = new JsonArray(); for (String l : is.getItemMeta().getLore()) lore.add(new JsonPrimitive(l)); itemObject.add("lore", lore); }//from w ww .j ava2 s . c om if (is.getItemMeta().hasEnchants()) { JsonArray enchantments = new JsonArray(); for (Enchantment enchantment : is.getItemMeta().getEnchants().keySet()) { JsonObject ench = new JsonObject(); ench.addProperty("enchantment", enchantment.getName()); ench.addProperty("level", is.getItemMeta().getEnchants().get(enchantment)); enchantments.add(ench); } itemObject.add("enchantments", enchantments); } return itemObject; }
From source file:com.exorath.simpleapi.impl.serverlist.GameServerImpl.java
License:Apache License
public JsonObject serializeToJson() { JsonObject object = new JsonObject(); object.addProperty("bungee", getBungeeName()); object.addProperty("joinable", isJoinable()); object.addProperty("playable", isPlayable()); object.addProperty("maxplayers", getPlayerAmount()); JsonArray playersArray = new JsonArray(); players.forEach(p -> playersArray.add(new JsonParser().parse(p.serialize()))); JsonArray extraLoreArray = new JsonArray(); extraLore.forEach(line -> extraLoreArray.add(new JsonPrimitive(line))); return object; }
From source file:com.exsoloscript.challonge.gson.OffsetDateTimeAdapter.java
License:Apache License
@Override public JsonElement serialize(OffsetDateTime offsetDateTime, Type type, JsonSerializationContext jsonSerializationContext) { String s = offsetDateTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME); return new JsonPrimitive(s); }
From source file:com.facebook.buck.rules.BuildInfoRecorder.java
License:Apache License
private String toJson(Iterable<String> values) { JsonArray out = new JsonArray(); for (String str : values) { out.add(new JsonPrimitive(str)); }//w w w . ja va2 s . co m return out.toString(); }
From source file:com.facebook.buck.rules.BuildInfoRecorder.java
License:Apache License
private String toJson(Multimap<String, String> multimap) { JsonObject out = new JsonObject(); for (Map.Entry<String, Collection<String>> entry : multimap.asMap().entrySet()) { JsonArray values = new JsonArray(); for (String value : entry.getValue()) { values.add(new JsonPrimitive(value)); }//from www . ja v a 2 s .c o m out.add(entry.getKey(), values); } return out.toString(); }
From source file:com.fatboyindustrial.gsonjavatime.InstantConverter.java
License:Open Source License
/** * Gson invokes this call-back method during serialization when it encounters a field of the specified type. * <p>//from www. j a v a2 s.c o m * * In the implementation of this call-back method, you should consider invoking * {@link JsonSerializationContext#serialize(Object, Type)} method to create JsonElements for any non-trivial field of the * {@code src} object. However, you should never invoke it on the {@code src} object itself since that will cause an * infinite loop (Gson will call your call-back method again). * * @param src the object that needs to be converted to Json. * @param typeOfSrc the actual type (fully genericized version) of the source object. * @return a JsonElement corresponding to the specified object. */ @Override public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(getFormatter().format(src)); }
From source file:com.fatboyindustrial.gsonjavatime.LocalDateConverter.java
License:Open Source License
/** * Gson invokes this call-back method during serialization when it encounters a field of the specified type. * <p>// w w w . j a v a2 s. c om * * In the implementation of this call-back method, you should consider invoking * {@link JsonSerializationContext#serialize(Object, Type)} method to create JsonElements for any non-trivial field of the * {@code src} object. However, you should never invoke it on the {@code src} object itself since that will cause an * infinite loop (Gson will call your call-back method again). * * @param src the object that needs to be converted to Json. * @param typeOfSrc the actual type (fully genericized version) of the source object. * @return a JsonElement corresponding to the specified object. */ @Override public JsonElement serialize(LocalDate src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(getFormatter().format(src)); }
From source file:com.fatboyindustrial.gsonjavatime.LocalDateTimeConverter.java
License:Open Source License
/** * Gson invokes this call-back method during serialization when it encounters a field of the specified type. * <p>//from ww w . ja va 2 s .c om * * In the implementation of this call-back method, you should consider invoking * {@link JsonSerializationContext#serialize(Object, Type)} method to create JsonElements for any non-trivial field of the * {@code src} object. However, you should never invoke it on the {@code src} object itself since that will cause an * infinite loop (Gson will call your call-back method again). * * @param src the object that needs to be converted to Json. * @param typeOfSrc the actual type (fully genericized version) of the source object. * @return a JsonElement corresponding to the specified object. */ @Override public JsonElement serialize(LocalDateTime src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(getFormatter().format(src)); }