BlazeDs Object Mapping from Flex to Java - actionscript-3

We can map flex to java objects using remoteclass
I have flex object with attributes a, b , c all have datatype as string
So i also need to have Java object with following atributes a , b , c with string datatype
Is it compulsory to have exact number of attributes with similar datatype?
If not then what error does it throw?

You should use all attributes of JAVA object in your flex object otherwise you will encounter "ArgumentError: Error #1063: Argument count mismatch on entities"
Also flex object can have additional attributes which are not defined in JAVA object

Related

JGraphT - Is it possible to export List properties of Vertices & Edges as JSON

I am using JGraphT to create a graph with custom vertices and edge classes. One of the property of the vertex and edge class is a List of String. Everything works fine till I try to export the graph as JSON.
The list property does not get serialized to the proper form.
I have used the vertex and edge attribute provider on the JSOnExporter. the functions are getting called. I am returning the Map as expected with the property names and their values.
The issue arises with the List property. If I just pass the List with AttributeType as unknown (I don't see an array attribute type), it calls the toString method on the List and puts the value in the JSON, which is not a JSON array value.
If I convert the list into a valid JSON string with Jackson, ex: ["abc","def"], in exported JSON it comes out as "[\"abc\",\"def\"]" which is not a correct representation.
Is it at all possible to export Lists as JSON arrays in the current implementation of JGraphT JSONExporter

jackson library to accept currency and percent as valid json

val jsonObject = new org.json.JSONObject("{\"name\":\"abc\",\"Estd date\":\"23.06.1995\",\"GrowthRate\":50%}")
println(jsonObject)
new ObjectMapper().readTree("{\"name\":\"abc\",\"Estd date\":\"23.06.1995\",\"GrowthRate\":50%}")
Exception in thread "main" com.fasterxml.jackson.core.JsonParseException: Unexpected character ('%' (code 37)): was expecting comma to separate OBJECT entries
What can be done to have the same behavior as that of JSONObject? We have some restrictions due to which we cannot use JSONObject. Any help with this?
Is there a way we can do this using custom serializer? Currency symbols like $50 should also be parsed.
I am using jackson-databind-2.6.7.1.jar
Expressions like 50% or 10$ must be transported as string [1].
new ObjectMapper().readTree("{\"name\":\"abc\",\"Estd date\":\"23.06.1995\",\"GrowthRate\":\"50%\"}")
will work.
[1]
A JSON value MUST be an object, array, number, or string, or one of
the following three literal names: false null true
https://www.rfc-editor.org/rfc/rfc7159#page-5
Related:
What is the standard for formatting currency values in JSON?
Jackson- Json parsing failure because of extra quotes in values

What is the difference between an ArrayItems vs SingleItems in Jackson JsonSchema module?

In the documentation, ArrayItems is described as
When this attribute value is an array of jsonSchemas and the instance value is an array, each position in the instance array MUST conform to the jsonSchema in the corresponding position for this array
and SingleItems as
When this attribute value is a jsonSchema and the instance value is an array, then all the items in the array MUST be valid according to the jsonSchema.
but I don't really understand what the attribute value and instance is referring to. If I just want to know the data types of items in the array, which one should I use?

Injecting annotation values from ResourceBundle

How can I read a value for an annotation from a ResourceBundle?
Instead of using a fixed value for #JsonProperty("myPropertyName") I wonder if it is possible to do something like #JsonProperty(env.getProperty("json.property.myproperty")).
No, it is not possible. The java language specification states
It is a compile-time error if the return type of a method declared in
an annotation type is not one of the following: a primitive type,
String, Class, any parameterized invocation of Class, an enum type
(§8.9), an annotation type, or an array type (§10) whose element type
is one of the preceding types.
Spring processes your beans at runtime. The annotation needs to have its attribute values at compile time.

Parsing JSON objects of unknown type with AutoBean on GWT

My server returns a list of objects in JSON. They might be Cats or Dogs, for example.
When I know that they'll all be Cats, I can set the AutoBeanCodex to work easily. When I don't know what types they are, though... what should I do?
I could give all of my entities a type field, but then I'd have to parse each entity before passing it to the AutoBeanCodex, which borders on defeating the point. What other options do I have?
Just got to play with this the other day, and fought it for a few hours, trying #Category methods and others, until I found this: You can create a property of type Splittable, which represents the underlying transport type that has some encoding for booleans/Strings/Lists/Maps. In my case, I know some enveloping type that goes over the wire at design time, and based on some other property, some other field can be any number of other autobeans.
You don't even need to know the type of the other bean at compile time, you could get values out using Splittable's methods, but if using autobeans anyway, it is nice to define the data that is wrapped.
interface Envelope {
String getStatus();
String getDataType();
Splittable getData();
}
(Setters might be desired if you sending data as well as recieving - encoding a bean into a `Splittable to send it in an envelope is even easier than decoding it)
The JSON sent over the wire is decoded (probably using AutoBeanCodex) into the Envelope type, and after you've decided what type must be coming out of the getData() method, call something like this to get the nested object out
SpecificNestedBean bean = AutoBeanCodex.decode(factory,
SpecificNestedBean.class,
env.getData()).as();
The Envelope type and the nested types (in factory above) don't even need to be the same AutoBeanFactory type. This could allow you to abstract out the reading/writing of envelopes from the generic transport instance, and use a specific factory for each dataType string property to decode the data's model (and nested models).