jenkinsci / stapler

Stapler web framework
BSD 2-Clause "Simplified" License
161 stars 103 forks source link

Export JSONObject with stapler throw NotExportableException exception when there is a field with null value. #172

Open aHenryJard opened 5 years ago

aHenryJard commented 5 years ago

Using JSONObject in classes with annotation @ExportedBean works fine except when there is a field with null value.

Having a field with null value is correct in JSON format. So JSONObject with JSONNull should be exportable as other JSONObject.

The exception raised is:

org.kohsuke.stapler.export.NotExportableException: class net.sf.json.JSONNull doesn't have @ExportedBean

    at org.kohsuke.stapler.export.Property.writeValue(Property.java:298)
    at org.kohsuke.stapler.export.Property.writeValue(Property.java:168)
    at org.kohsuke.stapler.export.Property.writeValue(Property.java:266)
    at org.kohsuke.stapler.export.Property.writeValue(Property.java:168)
    at org.kohsuke.stapler.export.Property.writeTo(Property.java:153)
    at org.kohsuke.stapler.export.Model.writeNestedObjectTo(Model.java:223)
    at org.kohsuke.stapler.export.Model.writeTo(Model.java:194)
    at org.kohsuke.stapler.export.Model.writeTo(Model.java:214)
    at org.kohsuke.stapler.export.Model.writeTo(Model.java:182)

PR with test to reproduce the issue: https://github.com/stapler/stapler/pull/173

batmat commented 2 years ago

Done with https://github.com/stapler/stapler/pull/173 I assume?

timja commented 2 years ago

There's a test case added now that reproduces the issue @batmat

It's ignored as the issue wasn't fixed: https://github.com/stapler/stapler/blob/master/core/src/test/java/org/kohsuke/stapler/export/JSONDataWriterTest.java#L105