apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chinmay Kolhatkar (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (APEXMALHAR-1979) Ability to generate compiled class from given json schema
Date Thu, 28 Jan 2016 08:17:39 GMT

    [ https://issues.apache.org/jira/browse/APEXMALHAR-1979?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15120998#comment-15120998
] 

Chinmay Kolhatkar commented on APEXMALHAR-1979:
-----------------------------------------------

h3. Objective
Objective of this utility is to provide a way to user to generate a compiled and loadable
bean class on the fly by providing schema of the bean in JSON format.

h3. Usecase
Often it is required that the bean class to be used for transfer of data across streams are
not available at compiled time or the schema is provided to user but not the class object
of it.
This utility gives a way to use to create a compiled and directly loadable bean class object
by providing a simple JSON based schema.
In effect, the utility provides a way to bridge a gap between a schema definition and a compiled
bean class.

h3. Prereq/Requirements
org.apache.xbean:xbean-asm5-shaded

h3.Design/Functionality
Name of the utility class is com.datatorrent.lib.util.BeanClassGenerator which provides the
functionality. This will be part of malhar-library.
The class provides following functionality:
1. Generate a bean class object using simple JSON schema provided. Return a bean class as
a byte[].
2. Read the byte[] and fully qualified class name(fqcn) and return a Class object for given
fqcn.

The generation of class is done using asm5 library of apache xbean.

Schema definition using JSON will like following:
{code}
{
       "fqcn":"<qualified class name>",
       "fields": [
         {
           "name":"field1",
           "type":"long"
         },
         {
           "name":"field2",
           "type": "java.lang.String"
         } 
       ]
 }
{code}

Supported types identified in "type" JSON field are:
      boolean, char, byte, short, int, float, long, double, any fqcn of java object.
For eg.
  - a String object in bean class should have type "java.lang.String".
  - a int in bean class should have type "int"

Following methods will be added to the generated class:
    a. Getter/Setter methods for given fields.
    b. simple toString - Generate string equivalent for all the fields
    c. hashCode method - calculate the overall hashCode using individual field hashcodes,
similar to how String.hashCode generates hashCode of string using chars in it.
    d. equals method - Similar to how String.equals method has done it using individual char.


> Ability to generate compiled class from given json schema
> ---------------------------------------------------------
>
>                 Key: APEXMALHAR-1979
>                 URL: https://issues.apache.org/jira/browse/APEXMALHAR-1979
>             Project: Apache Apex Malhar
>          Issue Type: New Feature
>            Reporter: Chinmay Kolhatkar
>            Assignee: Chinmay Kolhatkar
>
> Ability to generate compiled class from given json schema.
> Will add the details on json schema soon.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message