Quantcast
Channel: JetBrains Developer Community : Thread List - IntelliJ IDEA Users
Viewing all articles
Browse latest Browse all 5661

Code generation for Jackson stream parsing with live template

$
0
0

I would like to use live template to generate stream parsing code.

 

Below is what I want to achieve, assume there is a json,

{

     "type":1,

     "content":"abc"

     .....

}

 

In Intellij, I would like to generate code to parse above Json. I type

{"type","content", ....}

then .<template> name and press Tab. Intellij generates code as below

 

//----Start generated code-----

 

      while(parser.nextToken() != JsonToken.END_OBJECT){

            String fieldName = parser.getCurrentName();

            // Let's move to value

            parser.nextToken();

 

            if("type".equals(fieldName)){

                //Tab selection

            }else if("content".equals(fieldName)){

                //Tab selection

            }

            ............

            else{

                parser.skipChildren();

            }

        }

//----End generated code-----

 

I found that such as  $ARRAY$[$INDEX$], but there is no way to evaluate the value of the variable.

Do anyone have an idea to write such live template? Thanks!


Viewing all articles
Browse latest Browse all 5661

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>