/** * Encode this chat message to its textual JSON representation. * * @return The encoded representation. */ public String encode() { return object.toJSONString(); }
public String toString(){ return toJSONString(); }
public String toJSONString(){ return toJSONString(this); }
public StatusResponseMessage(JSONObject json) { this.json = json.toJSONString(); }
public static String toString(String key,Object value){ StringBuffer sb = new StringBuffer(); toJSONString(key, value, sb); return sb.toString(); }
@Override public byte[] mapRecord(Tuple tuple) { JSONObject obj = new JSONObject(); if (this.columnFields != null) { for (String field : this.columnFields) { obj.put(field, tuple.getValueByField(field)); } } return obj.toJSONString().getBytes(); }
@Override public byte[] mapRecord(TridentTuple tuple) { JSONObject obj = new JSONObject(); if (this.columnFields != null) { for (String field : this.columnFields) { obj.put(field, tuple.getValueByField(field)); } } return obj.toJSONString().getBytes(); }
@Override public String toString() { // Create a new json object JSONObject obj = new JSONObject(); obj.put("buildNumber", buildNumber); obj.put("download", download.toString()); // Return parsed json to string return obj.toJSONString(); }
public static void main(String[] args) { // convert Java to json JSONObject root = new JSONObject(); root.put("message", "Hi"); JSONObject place = new JSONObject(); place.put("name", "World!"); root.put("place", place); String json = root.toJSONString(); System.out.println(json); System.out.println(); // convert json to Java JSONObject obj = (JSONObject) JSONValue.parse(json); String message = (String) obj.get("message"); place = (JSONObject) obj.get("place"); String name = (String) place.get("name"); System.out.println(message + " " + name); } }
@GET @Path( "/browse" ) @Produces( { APPLICATION_JSON } ) public Response browse() { String path = "/"; try { path = controller.browse(); } catch ( Exception e ) { // Do nothing } JSONObject jsonObject = new JSONObject(); jsonObject.put( "path", path ); return Response.ok( jsonObject.toJSONString() ).build(); } }
public String getCurrentUser() { JSONObject jsonObject = new JSONObject(); jsonObject.put( "username", getPropsUI().getLastRepositoryLogin() ); return jsonObject.toJSONString(); }
@SuppressWarnings("unchecked") public String toJSONString() { JSONObject data = new JSONObject(); data.put("price", super.getPrice()); data.put("maximumWeight", this.getMaximumWeight()); return data.toJSONString(); }
@SuppressWarnings("unchecked") @Override public String toJSONString() { JSONObject data = new JSONObject(); data.put("taxBasisCalculation", this.getTaxBasisCalculation().name()); return data.toJSONString(); }
public static String getJsonWithUpdatedResources(String jsonConf, Map<String, Double> resourceUpdates) { try { JSONParser parser = new JSONParser(); Object obj = parser.parse(jsonConf); JSONObject jsonObject = (JSONObject) obj; Map<String, Double> componentResourceMap = (Map<String, Double>) jsonObject.getOrDefault( Config.TOPOLOGY_COMPONENT_RESOURCES_MAP, new HashMap<String, Double>() ); for (Map.Entry<String, Double> resourceUpdateEntry : resourceUpdates.entrySet()) { if (NormalizedResources.RESOURCE_NAME_NORMALIZER.getResourceNameMapping().containsValue(resourceUpdateEntry.getKey())) { // if there will be legacy values they will be in the outer conf jsonObject.remove(getCorrespondingLegacyResourceName(resourceUpdateEntry.getKey())); componentResourceMap.remove(getCorrespondingLegacyResourceName(resourceUpdateEntry.getKey())); } componentResourceMap.put(resourceUpdateEntry.getKey(), resourceUpdateEntry.getValue()); } jsonObject.put(Config.TOPOLOGY_COMPONENT_RESOURCES_MAP, componentResourceMap); return jsonObject.toJSONString(); } catch (ParseException ex) { throw new RuntimeException("Failed to parse component resources with json: " + jsonConf); } }
@SuppressWarnings("unchecked") @Override public String toJSONString() { JSONObject data = new JSONObject(); data.put("host", this.getHost()); data.put("port", this.getPort()); data.put("protocol", this.getProtocol()); data.put("username", this.getUsername()); data.put("smtpAuth", this.isSmtpAuth()); data.put("starttls", this.isStarttls()); data.put("password", this.getPassword()); return data.toJSONString(); }
/** * Writes the statistics of the player into its statistics file. * * @param player the player to write the statistics file from */ @Override public void writeStatistics(GlowPlayer player) { File file = getPlayerFile(player.getUniqueId()); StatisticMap map = player.getStatisticMap(); JSONObject json = new JSONObject(map.getValues()); try { FileWriter writer = new FileWriter(file, false); writer.write(json.toJSONString()); writer.close(); } catch (IOException e) { e.printStackTrace(); } } }
public String createConnection() { CompletableFuture<String> future = new CompletableFuture<>(); spoonSupplier.get().getShell().getDisplay().asyncExec( () -> { DatabaseDialog databaseDialog = new DatabaseDialog( spoonSupplier.get().getShell(), new DatabaseMeta() ); databaseDialog.open(); DatabaseMeta databaseMeta = databaseDialog.getDatabaseMeta(); if ( databaseMeta != null ) { if ( !isDatabaseWithNameExist( databaseMeta, true ) ) { addDatabase( databaseMeta ); future.complete( databaseMeta.getName() ); } else { DatabaseDialog.showDatabaseExistsDialog( spoonSupplier.get().getShell(), databaseMeta ); } } future.complete( "None" ); } ); JSONObject jsonObject = new JSONObject(); try { jsonObject.put( "name", future.get() ); return jsonObject.toJSONString(); } catch ( Exception e ) { jsonObject.put( "name", "None" ); return jsonObject.toJSONString(); } }
public String editDatabaseConnection( String database ) { CompletableFuture<String> future = new CompletableFuture<>(); spoonSupplier.get().getShell().getDisplay().asyncExec( () -> { DatabaseMeta databaseMeta = getDatabase( database ); String originalName = databaseMeta.getName(); DatabaseDialog databaseDialog = new DatabaseDialog( spoonSupplier.get().getShell(), databaseMeta ); databaseDialog.open(); if ( !isDatabaseWithNameExist( databaseMeta, false ) ) { save(); future.complete( databaseMeta.getName() ); } else { DatabaseDialog.showDatabaseExistsDialog( spoonSupplier.get().getShell(), databaseMeta ); databaseMeta.setName( originalName ); databaseMeta.setDisplayName( originalName ); future.complete( originalName ); } } ); JSONObject jsonObject = new JSONObject(); try { jsonObject.put( "name", future.get() ); return jsonObject.toJSONString(); } catch ( Exception e ) { jsonObject.put( "name", "None" ); return jsonObject.toJSONString(); } }
@SuppressWarnings("unchecked") @Override public String toJSONString() { JSONObject data = new JSONObject(); data.put("shipBaseType", this.getShippingBasisType().name()); data.put("shipOptionPriceType", this.getShippingOptionPriceType().name()); data.put("shipType", this.getShippingType().name()); data.put("shipPackageType", this.getShippingPackageType().name()); if(shipFreeType!=null) { data.put("shipFreeType", this.getFreeShippingType().name()); } data.put("shipDescription", this.getShippingDescription().name()); data.put("boxWidth", this.getBoxWidth()); data.put("boxHeight", this.getBoxHeight()); data.put("boxLength", this.getBoxLength()); data.put("boxWeight", this.getBoxWeight()); data.put("maxWeight", this.getMaxWeight()); data.put("freeShippingEnabled", this.freeShippingEnabled); data.put("orderTotalFreeShipping", this.orderTotalFreeShipping); data.put("handlingFees", this.handlingFees); data.put("taxOnShipping", this.taxOnShipping); return data.toJSONString(); }
public JSONArray storeRecentSearch( String recentSearch ) { JSONArray recentSearches = getRecentSearches(); try { if ( recentSearch == null || recentSearches.contains( recentSearch ) ) { return recentSearches; } recentSearches.add( recentSearch ); if ( recentSearches.size() > 5 ) { recentSearches.remove( 0 ); } PropsUI props = PropsUI.getInstance(); String jsonValue = props.getRecentSearches(); JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = jsonValue != null ? (JSONObject) jsonParser.parse( jsonValue ) : new JSONObject(); jsonObject.put( getLogin(), recentSearches ); props.setRecentSearches( jsonObject.toJSONString() ); } catch ( Exception e ) { e.printStackTrace(); } return recentSearches; }