Repository: joelittlejohn/jsonschema2pojo (java)

Issue:
question mark as part of json property name means I'm unable to generate Java classes
I'm consuming a schema JSON from a vendor I don't control.  The JSON contains some fields ending with a question mark (property-name?). this is of course not viewed as legal by the plugin.  When the field is named the same as another property, but just with the question mark added, I get a message "trying to create the same field twice: <propertyName>.  If it is just a property ending in the question mark the IllegalArgumentException is "Path not present: <property-name>".  

I have a ticket open with the vendor to get them to correct their schema api, but I have no hope that they will actually do it.

Even trying to manually use the question mark in a Java field name is not legal, so I can't think of a "good " way for the plugin to handle it.  I think it would be sufficient to be able to tell the plugin to skip certain properties though, such as ones containing the question mark.  Another option would be for me to be able to specify a different name for them to generate with.  That would be better than erroring out in my case.  The alternative is for me to manually alter the vendor's schema, or to tediously write Java code to remove/change the offending properties.  

Pull request:
Add support for property names containing question mark(s)
Closes #1513

Patch:
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/JsonPointerUtils.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/JsonPointerUtils.java
index dc923f2b..b2fce9ec 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/JsonPointerUtils.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/JsonPointerUtils.java
@@ -29,6 +29,7 @@ public class JsonPointerUtils {
         put("/", "~1");
         put("#", "~2");
         put(".", "~3");
+        put("?", "~4");
     }};
 
     public static String encodeReferenceToken(final String s) {


Test patch:
diff --git a/jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/JsonPointerUtilsTest.java b/jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/JsonPointerUtilsTest.java
index c286cfc6..56423aad 100644
--- a/jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/JsonPointerUtilsTest.java
+++ b/jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/JsonPointerUtilsTest.java
@@ -26,13 +26,13 @@ public class JsonPointerUtilsTest {
 
     @Test
     public void testEncodeReferenceToken() {
-        assertThat(JsonPointerUtils.encodeReferenceToken("com/vsv#..."), is("com~1vsv~2~3~3~3"));
-        assertThat(JsonPointerUtils.encodeReferenceToken("~1~2~01~3"), is("~01~02~001~03"));
+        assertThat(JsonPointerUtils.encodeReferenceToken("com/vsv#...?"), is("com~1vsv~2~3~3~3~4"));
+        assertThat(JsonPointerUtils.encodeReferenceToken("~1~2~01~3~4"), is("~01~02~001~03~04"));
     }
 
     @Test
     public void testDecodeReferenceToken() {
-        assertThat(JsonPointerUtils.decodeReferenceToken("com~1vsv~2~3~3~3"), is("com/vsv#..."));
-        assertThat(JsonPointerUtils.decodeReferenceToken("~01~02~001~03"), is("~1~2~01~3"));
+        assertThat(JsonPointerUtils.decodeReferenceToken("com~1vsv~2~3~3~3~4"), is("com/vsv#...?"));
+        assertThat(JsonPointerUtils.decodeReferenceToken("~01~02~001~03~04"), is("~1~2~01~3~4"));
     }
 }
\ No newline at end of file
diff --git a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/PropertiesIT.java b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/PropertiesIT.java
index 00c5e334..a3a6d263 100644
--- a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/PropertiesIT.java
+++ b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/PropertiesIT.java
@@ -212,5 +212,6 @@ public class PropertiesIT {
         assertNotNull(generatedType.getDeclaredMethod("getFooBar"));
         assertNotNull(generatedType.getDeclaredMethod("get$RfcNumber"));
         assertNotNull(generatedType.getDeclaredMethod("getOrgHispDhisCommonFileTypeValueOptions"));
+        assertNotNull(generatedType.getDeclaredMethod("getGood"));
     }
 }
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/properties/propertiesWithSpecialCharacters.json b/jsonschema2pojo-integration-tests/src/test/resources/schema/properties/propertiesWithSpecialCharacters.json
index 9361455f..d30b82c4 100644
--- a/jsonschema2pojo-integration-tests/src/test/resources/schema/properties/propertiesWithSpecialCharacters.json
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/properties/propertiesWithSpecialCharacters.json
@@ -12,6 +12,9 @@
     },
     "org.hisp.dhis.common.FileTypeValueOptions" : {
       "type" : "string"
+    },
+    "good?" : {
+      "type" : "boolean"
     }
   }
 }