List of usage examples for com.google.gson JsonPrimitive JsonPrimitive
public JsonPrimitive(Character c)
From source file:RunnerRepository.java
License:Apache License
public static void saveUTLayout(Dimension size, Point p, int divloc) { JsonObject lay = getLayouts();/*from www.ja v a 2 s.c o m*/ lay.add("UTsize", new JsonPrimitive(size.getWidth() + " " + size.getHeight())); lay.add("UTlocation", new JsonPrimitive(p.getX() + " " + p.getY())); lay.add("UTh1splitlocation", new JsonPrimitive(divloc)); writeJSon(); }
From source file:HyperLogLog.java
public String ToJson() { Gson g = new Gson(); JsonObject elm = new JsonObject(); elm.addProperty("M", this.m); elm.addProperty("B", this.b); elm.addProperty("A", this.alpha); JsonArray registerArr = new JsonArray(); for (int i = 0; i < registers.length; i++) { registerArr.add(new JsonPrimitive(registers[i])); }// w ww. jav a 2s . c o m elm.add("R", registerArr); return g.toJson(elm); }
From source file:AddMethod.java
License:Open Source License
@Override public JsonElement onMethodCalled(String path, JsonElement value) throws JsonRpcException { try {//from w w w . j ava 2 s . com int newValue = value.getAsInt(); Logger.getLogger(AddMethod.class.getName()).log(Level.INFO, "Method called with: {0}", newValue); newValue++; return new JsonPrimitive(newValue); } catch (ClassCastException | IllegalStateException e) { throw new JsonRpcException(JsonRpcException.INVALID_PARAMS, e.getMessage()); } }
From source file:EAIJSONConverter.java
License:Open Source License
public JsonObject traversePS(SiebelPropertySet ps, JsonObject jObj) { JsonObject siebJSON = new JsonObject(); String propName;/* w ww. j av a2 s.com*/ String propVal; propName = ps.getFirstProperty(); while (propName != "") { propVal = ps.getProperty(propName); siebJSON.addProperty(propName, propVal); propName = ps.getNextProperty(); } JsonObject child; for (int i = 0; i < ps.getChildCount(); i++) { child = new JsonObject(); if (ps.getChild(i).getType().startsWith("ListOf-")) { JsonArray ja = new JsonArray(); for (int o = 0; o < ps.getChild(i).getChildCount(); o++) { ja.add(traversePS(ps.getChild(i).getChild(o), child)); } siebJSON.add(ps.getChild(i).getType().substring(7), ja); } else if (ps.getChild(i).getType().startsWith("StringList-")) { JsonArray ja = new JsonArray(); SiebelPropertySet auxps = ps.getChild(i); Enumeration e = auxps.getPropertyNames(); List list = Collections.list(e); Collections.sort(list); e = Collections.enumeration(list); while (e.hasMoreElements()) { String propName1 = (String) e.nextElement(); ja.add(new JsonPrimitive(auxps.getProperty(propName1))); } siebJSON.add(auxps.getType().substring(11), ja); } else { child = traversePS(ps.getChild(i), child); siebJSON.add(ps.getChild(i).getType(), child); } } return siebJSON; }
From source file:Call.java
License:Open Source License
@Override public void completed(boolean success) { if (success) { Logger.getLogger(Call.class.getName()).log(Level.INFO, "Call Connection completed!"); JsonPrimitive value = new JsonPrimitive(42); peer.call("theMethod", value, this, 5000); } else {//from www. jav a 2 s . com Logger.getLogger(Call.class.getName()).log(Level.SEVERE, "Call Connection failed!"); } }
From source file:CustomAudienceExample.java
License:Open Source License
public static void main(String[] args) { try {//from ww w .ja va2 s .c o m AdAccount account = new AdAccount(ACCOUNT_ID, context); CustomAudience audience = account.createCustomAudience().setName("Java SDK Test Custom Audience") .setDescription("Test Audience").setSubtype(EnumSubtype.VALUE_CUSTOM).execute(); // Audience payload schema JsonArray schema = new JsonArray(); schema.add(new JsonPrimitive("EMAIL_SHA256")); schema.add(new JsonPrimitive("PHONE_SHA256")); // Audience payload data JsonArray personA = new JsonArray(); personA.add(new JsonPrimitive(sha256("aaa@example.com"))); personA.add(new JsonPrimitive(sha256("1234567890"))); JsonArray personB = new JsonArray(); personB.add(new JsonPrimitive(sha256("bbb@example.com"))); personB.add(new JsonPrimitive(sha256("1234567890"))); JsonArray personC = new JsonArray(); personC.add(new JsonPrimitive(sha256("ccc@example.com"))); personC.add(new JsonPrimitive(sha256("1234567890"))); JsonArray data = new JsonArray(); data.add(personA); data.add(personB); data.add(personC); JsonObject payload = new JsonObject(); payload.add("schema", schema); payload.add("data", data); audience.createUser().setPayload(payload.toString()).execute(); System.out.println(audience.fetch()); Targeting targeting = new Targeting().setFieldCustomAudiences("[{id:" + audience.getId() + "}]"); Campaign campaign = account.createCampaign().setName("Java SDK Test Campaign") .setObjective(Campaign.EnumObjective.VALUE_LINK_CLICKS).setSpendCap(10000L) .setStatus(Campaign.EnumStatus.VALUE_PAUSED).execute(); AdSet adset = account.createAdSet().setName("Java SDK Test AdSet").setCampaignId(campaign.getFieldId()) .setStatus(AdSet.EnumStatus.VALUE_PAUSED) .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS).setDailyBudget(1000L) .setBidAmount(100L).setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_IMPRESSIONS) .setTargeting(targeting).setRedownload(true).requestAllFields().execute(); System.out.println(adset); AdImage image = account.createAdImage().addUploadFile("file", imageFile).execute(); AdCreative creative = account.createAdCreative().setTitle("Java SDK Test Creative") .setBody("Java SDK Test Creative").setImageHash(image.getFieldHash()) .setLinkUrl("www.facebook.com").setObjectUrl("www.facebook.com").execute(); Ad ad = account.createAd().setName("Java SDK Test ad").setAdsetId(Long.parseLong(adset.getId())) .setCreative(creative).setStatus("PAUSED").setBidAmount(100L).setRedownload(true).execute(); } catch (APIException e) { e.printStackTrace(); } }
From source file:abtlibrary.utils.as24ApiClient.JSON.java
License:Apache License
/** * Serialize//from w w w .j a v a2s. c o m * * @param src Date * @param typeOfSrc Type * @param context Json Serialization Context * @return Json Element */ @Override public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { if (src == null) { return JsonNull.INSTANCE; } else { return new JsonPrimitive(apiClient.formatDatetime(src)); } }
From source file:allout58.mods.techtree.tree.TechNodeGSON.java
License:Open Source License
@Override public JsonElement serialize(TechNode src, Type typeOfSrc, JsonSerializationContext context) { final JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("id", src.getId()); jsonObject.addProperty("name", src.getName()); jsonObject.addProperty("scienceRequired", src.getScienceRequired()); jsonObject.addProperty("description", src.getDescription()); final JsonArray jsonParents = new JsonArray(); for (final TechNode parent : src.getParents()) { final JsonPrimitive jsonParent = new JsonPrimitive(parent.getId()); jsonParents.add(jsonParent);/*from w w w . j a va 2 s . com*/ } jsonObject.add("parents", jsonParents); final JsonArray jsonItems = new JsonArray(); for (final ItemStack item : src.getLockedItems()) { jsonItems.add(context.serialize(item)); } jsonObject.add("lockedItems", jsonItems); return jsonObject; }
From source file:am.ik.categolj3.api.CategoLJ3ApiConfig.java
License:Apache License
@Bean Gson gson() {/*from ww w. j a v a 2 s . co m*/ return new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssX").registerTypeAdapter(OffsetDateTime.class, (JsonDeserializer<OffsetDateTime>) (json, type, context) -> DateTimeFormatter.ISO_OFFSET_DATE_TIME .parse(json.getAsString(), OffsetDateTime::from)) .registerTypeAdapter(OffsetDateTime.class, (JsonSerializer<OffsetDateTime>) (json, type, context) -> new JsonPrimitive(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(json))) .create(); }
From source file:angularBeans.util.AngularBeansUtil.java
License:Open Source License
public JsonElement serialize(LobWrapper src, Type typeOfSrc, JsonSerializationContext context) { LobWrapper lobWrapper = (LobWrapper) src; container = lobWrapper.getOwner();//from www . ja v a2s. co m String id = ""; Class clazz = container.getClass(); for (Method m : clazz.getMethods()) { if (m.getName().startsWith("get") || m.getName().startsWith("is")) { if (m.getReturnType().equals(LobWrapper.class)) { String field = AngularBeansUtil.obtainFieldNameFromAccessor(m.getName()); try { Call lobSource = new Call(container, m); if (!cache.getCache().containsValue(lobSource)) { id = String.valueOf(UUID.randomUUID()); cache.getCache().put(id, lobSource); } else { for (String idf : (cache.getCache().keySet())) { Call ls = cache.getCache().get(idf); if (ls.equals(lobSource)) { id = idf; // cache.getCache().remove(idf); // id = String.valueOf(UUID.randomUUID()); // cache.getCache().put(id, lobSource); break; } } continue; } } catch (Exception e) { e.printStackTrace(); } // else{ // return context.serialize(src); // } } } } return new JsonPrimitive("lob/" + id + "?" + Calendar.getInstance().getTimeInMillis()); }