Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spaces in field name causes Exception #1623

Open
solsticesurfer opened this issue Jul 19, 2024 · 4 comments
Open

Spaces in field name causes Exception #1623

solsticesurfer opened this issue Jul 19, 2024 · 4 comments

Comments

@solsticesurfer
Copy link

When parsing a json file that has spaces in the field names, the following is thrown: java.lang.IllegalArgumentException: Path not present:. It's then followed by the URL-encoded version of the property name (e.g. "My%20Property"). Unfortunately, I don't have control over the source and design of the payload.

I've scoured through the documentation, issues, and source but haven't found a solution. I thought this might be covered under propertyWordDelimiters but that doesn't seem to be the case.

Ideally, I would like to either remove the space in a property name or replace it with another valid character.

Is this possible or is there a better approach to dealing with this scenario?

@sdegroot
Copy link

sdegroot commented Jul 22, 2024

I have a similar issue with properties that have a question mark in them :)
This is since 1.1.2, where it worked at 1.1.1

@joelittlejohn
Copy link
Owner

There are some characters that need to be escaped because they can the way that JSON Pointer is resolved. The next release (1.2.2) will fix question marks. For the change that was needed, see #1522.

@solsticesurfer What version of jsonschema2pojo are you using? Spaces in the property name should work. If you can provide a minimal snippet of JSON Schema that fails, that would be good.

@unkish
Copy link
Collaborator

unkish commented Jul 23, 2024

@joelittlejohn spaces in property names work for JSON Schema but fail with regular json, ie. generating pojo's from following json fails:

{
   "a b": "text"
}

whilst everything is OK with json schema:

{
  "type" : "object",
  "properties" : {
    "a b" : {
      "type" : "string"
    }
  }
}

@solsticesurfer
Copy link
Author

@joelittlejohn Appreciate the help and thank you. This is using version 1.2.1 via Gradle. This JSON sample below is enough to reproduce the behavior.

As @unkish pointed out, the conversion fails when calling Json2Pojo.convertJsonToJavaClass() due to the field having a space. Removing the last line in the sample results in the target class being created as expected.

Unfortunately, the schema is not known before processing and is not constant, so using json schema is not an option.

I do see that the field with the underscores is successfully interpreted and that the result has the underscores removed. If we had the ability to specify a substitution rule to use in a case like this, it would resolve the problem.

{
    "fieldA": 123,
    "fieldB": 456,
    "My_Custom_Field": "abcdef",    
    "My Other Field": "abcdef"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants