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

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

    XMLWordPrintableJSON

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor
    • Resolution: Not A Problem
    • Affects Version/s: 2.5.0
    • Fix Version/s: None
    • Component/s: JSON
    • Labels:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: