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

JsonBuilder or JsonOutput incompatible with JodaTime

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.5
    • 4.0.0
    • JSON
    • JVM: 1.8.0_65 (Oracle)
      Mac OS X 10.11.1 (El Capitan)

    Description

      Using groovy's built-in methods to serialize Joda DateTime to JSON always conclude in a StackOverflowError.

      ExampleMethod
      package com.mgd
      
      import groovy.json.JsonOutput
      
      import org.joda.time.DateTime
      import org.joda.time.format.DateTimeFormat
      import org.joda.time.format.DateTimeFormatter
      
      class JodaBugJson {
      
      	public static void main(String[] args) {
      		DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS z")
      
      		DateTime dt = formatter.parseDateTime("2015-11-20 13:37:21.123 EST")
      
      		//String json = new JsonBuilder(dt).toString()	//same outcome
      		String json = JsonOutput.toJson(dt)
      		println json
      	}
      }
      

      Running the above will result in :

      Error
      Exception in thread "main" java.lang.StackOverflowError
      	at org.codehaus.groovy.reflection.ClassInfo.getClassInfo(ClassInfo.java:119)
      	at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:261)
      	at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:871)
      	at org.codehaus.groovy.runtime.DefaultGroovyMethods.getMetaPropertyValues(DefaultGroovyMethods.java:364)
      	at org.codehaus.groovy.runtime.DefaultGroovyMethods.getProperties(DefaultGroovyMethods.java:383)
      	at groovy.json.JsonOutput.writeObject(JsonOutput.java:290)
      	at groovy.json.JsonOutput.writeMap(JsonOutput.java:424)
      	at groovy.json.JsonOutput.writeObject(JsonOutput.java:294)
      	at groovy.json.JsonOutput.writeMap(JsonOutput.java:424)
      	at groovy.json.JsonOutput.writeObject(JsonOutput.java:294)
      	at groovy.json.JsonOutput.writeMap(JsonOutput.java:424)
              ...
      

      Whether this be only the date, or an object including a Joda DateTime the outcome is the same.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              jppellerin Jean-Philippe Pellerin
              Votes:
              3 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: