public static List<Message> decodePayload(final String jsonString) { if (jsonString == null || jsonString.trim().length() == 0) return Collections.emptyList(); final JSONValue val = JSONParser.parseStrict(jsonString); if (val == null || val.isArray() == null) { throw new RuntimeException("illegal payload: must be JSONArray"); } final JSONArray jsonArray = val.isArray(); final List<Message> messageList = new ArrayList<Message>(jsonArray.size()); for (int i = 0; i < jsonArray.size(); i++) { messageList.add(decodeCommandMessage(GWTJSON.wrap(jsonArray.get(i)))); } return messageList; }
public static <Type> Set<Type> toSet(JSONValue value, AbstractJsonEncoderDecoder<Type> encoder) { if (value == null || value.isNull() != null) { return null; } JSONArray array = asArray(value); HashSet<Type> rc = new HashSet<Type>(array.size() * 2); int size = array.size(); for (int i = 0; i < size; i++) { rc.add(encoder.decode(array.get(i))); } return rc; }
protected MultiPath(final JSONObject node, final ValidationContext ctx) throws ValidationException { super(ShapeType.MULTI_PATH, node, ctx); final JSONValue pval = node.get("path-list"); if (null != pval) { final JSONArray list = pval.isArray(); if (null != list) { final int size = list.size(); for (int i = 0; i < size; i++) { final JSONValue lval = list.get(i); if (null != lval) { final JSONArray path = lval.isArray(); if (null != path) { final PathPartListJSO pjso = path.getJavaScriptObject().cast(); add(new PathPartList(pjso, true)); } } } } } }
private static LightArray<ContactOrganisation> getContactOrganisationArray(JSONArray jsonArray) { LightArray<ContactOrganisation> array = CollectionFactory.constructArray(); if (jsonArray == null) { return array; } for (int i = 0; i < jsonArray.size(); i++) { array.push(getOrganisation(jsonArray.get(i).isObject())); } return array; }
public static byte[] toArray(JSONValue value, AbstractJsonEncoderDecoder<Byte> encoder) { if (value == null || value.isNull() != null) { return null; } if (value.isString() != null) { return Base64Codec.decode(value.isString().stringValue()); } JSONArray array = asArray(value); int size = array.size(); byte template[] = new byte[size]; for (int i = 0; i < size; i++) { template[i] = encoder.decode(array.get(i)); } return template; }
public static <Type> List<Type> toList(JSONValue value, AbstractJsonEncoderDecoder<Type> encoder) { if (value == null || value.isNull() != null) { return null; } JSONArray array = asArray(value); ArrayList<Type> rc = new ArrayList<Type>(array.size()); int size = array.size(); for (int i = 0; i < size; i++) { rc.add(encoder.decode(array.get(i))); } return rc; }
protected MultiPath(final JSONObject node, final ValidationContext ctx) throws ValidationException { super(ShapeType.MULTI_PATH, node, ctx); JSONValue pval = node.get("path-list"); if (null != pval) { final JSONArray list = pval.isArray(); if (null != list) { final int size = list.size(); for (int i = 0; i < size; i++) { final JSONValue lval = list.get(i); if (null != lval) { final JSONArray path = lval.isArray(); if (null != path) { PathPartListJSO pjso = path.getJavaScriptObject().cast(); add(new PathPartList(pjso, true)); } } } } } }
private static LightArray<ContactAddress> getAddressArray(JSONArray jsonArray) { LightArray<ContactAddress> array = CollectionFactory.constructArray(); if (jsonArray == null) { return array; } for (int i = 0; i < jsonArray.size(); i++) { array.push(getAddress(jsonArray.get(i).isObject())); } return array; }
public static byte[] toArray(JSONValue value, AbstractJsonEncoderDecoder<Byte> encoder) { if (value == null || value.isNull() != null) { return null; } if (value.isString() != null) { return Base64Codec.decode(value.isString().stringValue()); } JSONArray array = asArray(value); int size = array.size(); byte template[] = new byte[size]; for (int i = 0; i < size; i++) { template[i] = encoder.decode(array.get(i)); } return template; }
public static List<Message> decodePayload(final String jsonString) { if (jsonString == null || jsonString.trim().length() == 0) return Collections.emptyList(); final JSONValue val = JSONParser.parseStrict(jsonString); if (val == null || val.isArray() == null) { throw new RuntimeException("illegal payload: must be JSONArray"); } final JSONArray jsonArray = val.isArray(); final List<Message> messageList = new ArrayList<Message>(jsonArray.size()); for (int i = 0; i < jsonArray.size(); i++) { messageList.add(decodeCommandMessage(GWTJSON.wrap(jsonArray.get(i)))); } return messageList; }
public String getColumnValue( String columnName ) { for( int i=0; i<row.size(); i++ ) { JSONObject cellJson = row.get( i ).isObject(); if( cellJson.get( "column" ).isString().stringValue().equals( columnName ) ) return cellJson.get( "value" ).isString().stringValue(); } return null; }
public static <Type> List<Type> toList(JSONValue value, AbstractJsonEncoderDecoder<Type> encoder) { if (value == null || value.isNull() != null) { return null; } JSONArray array = asArray(value); ArrayList<Type> rc = new ArrayList<Type>(array.size()); int size = array.size(); for (int i = 0; i < size; i++) { rc.add(encoder.decode(array.get(i))); } return rc; }
protected MultiPath(final JSONObject node, final ValidationContext ctx) throws ValidationException { super(ShapeType.MULTI_PATH, node, ctx); final JSONValue pval = node.get("path-list"); if (null != pval) { final JSONArray list = pval.isArray(); if (null != list) { final int size = list.size(); for (int i = 0; i < size; i++) { final JSONValue lval = list.get(i); if (null != lval) { final JSONArray path = lval.isArray(); if (null != path) { final PathPartListJSO pjso = path.getJavaScriptObject().cast(); add(new PathPartList(pjso, true)); } } } } } }
protected <C, E> void parsePluralJsonReference( X targetEntity, ErraiPluralAttribute<? super X, C, E> attr, JSONArray attrJsonValues, ErraiEntityManager eem) { if (attrJsonValues == null || attrJsonValues.isNull() != null) return; Class<E> attributeElementType = attr.getElementType().getJavaType(); ErraiIdentifiableType<E> attrEntityType = eem.getMetamodel().entity(attributeElementType); // FIXME this is broken for Map attributes // TODO when we support Map attributes, we should get the attribute with getCollection()/getMap() to fix this warning Collection<E> collection = (Collection<E>) attr.createEmptyCollection(); for (int i = 0; i < attrJsonValues.size(); i++) { Key<E, ?> key = (Key<E, ?>) Key.fromJsonObject(eem, attrJsonValues.get(i).isObject(), true); logger.trace(" looking for " + key); E value = eem.getPartiallyConstructedEntity(key); if (value == null) { value = eem.find(key, Collections.<String,Object>emptyMap()); } collection.add(value); } attr.set(targetEntity, (C) collection); }
public String getColumnValue( String columnName ) { for( int i=0; i<row.size(); i++ ) { JSONObject cellJson = row.get( i ).isObject(); if( cellJson.get( "column" ).isString().stringValue().equals( columnName ) ) return cellJson.get( "value" ).isString().stringValue(); } return null; }
public static <Type> Set<Type> toSet(JSONValue value, AbstractJsonEncoderDecoder<Type> encoder) { if (value == null || value.isNull() != null) { return null; } JSONArray array = asArray(value); HashSet<Type> rc = new HashSet<Type>(array.size() * 2); int size = array.size(); for (int i = 0; i < size; i++) { rc.add(encoder.decode(array.get(i))); } return rc; }