Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8849

Provide a way to change property names when converting Pojo to JSON

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Not A Problem
    • 2.5.0
    • None
    • JSON
    • None

    Description

      I want to be able to override with something like the annotation JsonProperty to override how a property name should be serialized to Json. If the feature is already there then please add documentation. For example:

      @JsonProperty("test_one")
      int testOne
      
      @JsonProperty("test_two")
      int testTwo

      More information on the example: Jackson-Annotations 

      Reproducible Code

      Pojo.groovy

      class Pojo {
        int testOne
        int testTwo
      }

      Sample Run:

      JsonOutput.toJson(new Pojo(testOne: 1, testTwo: 1))
      
      // Output
      // ===> {"testTwo":1,"testOne":1}
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            bond_ Raviteja Lokineni
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: