joelittlejohn / jsonschema2pojo

Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
http://www.jsonschema2pojo.org
Apache License 2.0
6.23k stars 1.66k forks source link

Need description of where error is occurring in parsing #508

Open beirtipol opened 8 years ago

beirtipol commented 8 years ago

I'm trying to use this through Maven to generate classes from the Kodi schema http://kodi.wiki/view/JSON-RPC_API/v6

Schema file: kodischema.zip

When using 'jackson' style, I get this error but it does not give any indication as to which object is failing to parse Generation is erroring due to

generate (default) on project homer-kodi: Execution default of goal
org.jsonschema2pojo:jsonschema2pojo-maven-plugin:0.4.19:generate failed: 
trying to create the same field twice: additionalProperties

Pom config

<plugin>
    <groupId>org.jsonschema2pojo</groupId>
    <artifactId>jsonschema2pojo-maven-plugin</artifactId>
    <version>0.4.19</version>
    <configuration>
        <outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
        <sourceDirectory>src/main/resources</sourceDirectory>
        <targetPackage>com.kodi.json</targetPackage>
        <sourceType>json</sourceType>
        <annotationStyle>jackson</annotationStyle>
        <useCommonsLang3>true</useCommonsLang3>
    </configuration>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

If I use gson parsing, it generates java classes but many of the object types are duplicated with underscores after their names which makes them unusable.

joelittlejohn commented 8 years ago

I'm not sure what the format of this file is, but it doesn't appear to be a json schema. I don't think you're going to have any luck trying to use this schema with jsonschema2pojo.

Would it be possible to simply use some example json payloads instead? (and set the source type to JSON).

beirtipol commented 8 years ago

I was wondering about that. The API documentation describes it as a schema and it does appear to have the fields listed in the json schema reference so I presumed it was a different schema format.

I'll have to manually craft it up

On Fri, 26 Feb 2016, 20:32 Joe Littlejohn, notifications@github.com wrote:

Reopened #508 https://github.com/joelittlejohn/jsonschema2pojo/issues/508.

— Reply to this email directly or view it on GitHub https://github.com/joelittlejohn/jsonschema2pojo/issues/508#event-568159259 .

beirtipol commented 8 years ago

Still a valid request though? To output more information about the parsing error location

joelittlejohn commented 8 years ago

This is a bit tricky as the original source location is lost after we parse the document. The problem here is that your document has been parsed correctly, but the field name 'additionalProperties' conflicts with the name of the field we use to store additional (unrecognised) properties.

It looks like this document has some JSON schemas within it, even though the document itself is not a JSON schema. You seem to have used sourceType=JSON, but I don't think that's what you want (you need to supply an example payload if you use sourceType=JSON, not a schema).

Re providing more information for this kind of error, yes, I definitely think this is still a valid request. One thing we could do is print the schema that was being processed when the exception occurred. This should give you a much better chance of working out where the error is.