Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EDT:JSONConversionJavaGenerationAndRuntime"

(Java Plugins)
Line 1: Line 1:
 
==== Java Plugins  ====
 
==== Java Plugins  ====
JSON support is annotation based. Annotation generation is container based and only the handler and record containers generate JSON conversion code.
+
JSON support is annotation based. Annotation generation is container based and only the handler and record containers generate JSON conversion code. A JSONName annotation will be generated into a Java org.eclipse.edt.javart.json.JSON annotations for each record or handler field. The Java annotation will be used by the runtime to convert the field to/from JSON.
 +
convertToJSON: loops through each field creating a name value pair.
 +
convertFrom JSON first parses the 'JSON' string into intermediate objects. Then loops through the egl fields obtaining the value using the name from the JSON.name annotation. The runtime converts the JSON value into an EGL runtime value using information from the annotation.
  
  
 
===== org.eclipse.edt.gen.java.templates.jee:  =====
 
===== org.eclipse.edt.gen.java.templates.jee:  =====
The preGenAnnotations scan all fields for a JSONName annotation, if the annotation does not exist 1 is added to field.  
+
The preGenAnnotations scan all fields for an EGL JSONName annotation, if the annotation does not exist 1 is added to field.  
Annotation generation has a template for each annotation. When the JSONName annotation is encountered by the generator the JSONNameTemplate is used to generate the JSONName annotation runtime class. If the field has a getter method the annotation is generated on the getter, if no getter is present the annotation is generated on the field. The JSONName contains more than just the JSON name it also the field type and the constructor options so the convertFromJson can create a new instance of the field.
+
Annotation generation has a template for each annotation type. When the JSONName annotation is encountered by the generator the JSONNameTemplate is used to generate the JSON annotation runtime class. eglx.json.JsonName to org.eclipse.edt.javart.json.Json mapping resides in the nativeProperties. If the field has a getter method the annotation is generated on the getter, if no getter is present the annotation is generated on the field. The JSON annotation contains the JSON name, the field type, and the constructor options so the convertFromJson can create a new instance of the field.
  
  
 
===== org.eclipse.edt.runtime.java.jee:  =====
 
===== org.eclipse.edt.runtime.java.jee:  =====
The runtime contains the JSONLib which has code to convert from an EGL record, handler or dictionary to JSON.
+
The JSON string parser is located in org.eclipse.edt.javart.json. This parser converts the JSON string into the objects located in this package, then the JSONLib converts these objects to the EGL parts.
Dictionaries have no generated annotations.
+
The runtime contains eglx.json.JSONLib which has code to convert from an EGL record, handler or dictionary to JSON.
convertToJSON uses the JSONName annotation to obtain the name used in the json conversion.
+
*convertToJSON uses the JSONName annotation to obtain the name used in the json conversion. For each field the name is added to a JSON string then its value.
convertFromJson uses the clazz and asOptions option field to determine the type of field to create along with the name to get the json value from the name/value pairs.
+
*convertFromJson uses the clazz and asOptions option field to determine the type of field to create along with the name to get the json value from the name/value pairs.
 +
Dictionaries have no generated annotations values are converted based on the JSON type not the EGL type.

Revision as of 11:42, 17 July 2012

Java Plugins

JSON support is annotation based. Annotation generation is container based and only the handler and record containers generate JSON conversion code. A JSONName annotation will be generated into a Java org.eclipse.edt.javart.json.JSON annotations for each record or handler field. The Java annotation will be used by the runtime to convert the field to/from JSON. convertToJSON: loops through each field creating a name value pair. convertFrom JSON first parses the 'JSON' string into intermediate objects. Then loops through the egl fields obtaining the value using the name from the JSON.name annotation. The runtime converts the JSON value into an EGL runtime value using information from the annotation.


org.eclipse.edt.gen.java.templates.jee:

The preGenAnnotations scan all fields for an EGL JSONName annotation, if the annotation does not exist 1 is added to field. Annotation generation has a template for each annotation type. When the JSONName annotation is encountered by the generator the JSONNameTemplate is used to generate the JSON annotation runtime class. eglx.json.JsonName to org.eclipse.edt.javart.json.Json mapping resides in the nativeProperties. If the field has a getter method the annotation is generated on the getter, if no getter is present the annotation is generated on the field. The JSON annotation contains the JSON name, the field type, and the constructor options so the convertFromJson can create a new instance of the field.


org.eclipse.edt.runtime.java.jee:

The JSON string parser is located in org.eclipse.edt.javart.json. This parser converts the JSON string into the objects located in this package, then the JSONLib converts these objects to the EGL parts. The runtime contains eglx.json.JSONLib which has code to convert from an EGL record, handler or dictionary to JSON.

  • convertToJSON uses the JSONName annotation to obtain the name used in the json conversion. For each field the name is added to a JSON string then its value.
  • convertFromJson uses the clazz and asOptions option field to determine the type of field to create along with the name to get the json value from the name/value pairs.

Dictionaries have no generated annotations values are converted based on the JSON type not the EGL type.

Back to the top