jsonschema2pojo icon indicating copy to clipboard operation
jsonschema2pojo copied to clipboard

Error when `#` is inside property name (not present in the website generator)

Open dagyu opened this issue 3 years ago • 2 comments
trafficstars

Given this minimal json schema:

{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "foo#bar": {
      "type": "string"
    }
  }
}

If I try to generate the code using https://www.jsonschema2pojo.org/ I obtain the right generated classes but if I try to generate with maven plugin I get the error Path not present: foo.

To see in the detail what happens this is the stack trace obtained from the cli command:

./jsonschema2pojo-1.1.2/bin/jsonschema2pojo --source example.json --target java-gen
Exception in thread "main" java.lang.IllegalArgumentException: Path not present: foo
	at org.jsonschema2pojo.FragmentResolver.resolve(FragmentResolver.java:54)
	at org.jsonschema2pojo.FragmentResolver.resolve(FragmentResolver.java:52)
	at org.jsonschema2pojo.FragmentResolver.resolve(FragmentResolver.java:31)
	at org.jsonschema2pojo.SchemaStore.create(SchemaStore.java:66)
	at org.jsonschema2pojo.SchemaStore.create(SchemaStore.java:140)
	at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:78)
	at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:41)
	at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:70)
	at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:38)
	at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:121)
	at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:66)
	at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:83)
	at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:38)
	at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:83)
	at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:76)
	at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:38)
	at org.jsonschema2pojo.SchemaMapper.generate(SchemaMapper.java:92)
	at org.jsonschema2pojo.Jsonschema2Pojo.generate(Jsonschema2Pojo.java:79)
	at org.jsonschema2pojo.cli.Jsonschema2PojoCLI.main(Jsonschema2PojoCLI.java:58)

The error is caused by the # in the property name but why when I use the website the error disappear? How can I obtain the website behaviour without getting any error?

dagyu avatar Jul 15 '22 11:07 dagyu

Hi

It's a duplicate of https://github.com/joelittlejohn/jsonschema2pojo/issues/1402 and is related to https://github.com/joelittlejohn/jsonschema2pojo/issues/1404.

How can I obtain the website behaviour without getting any error?

  • use jsonschema2pojo version 1.1.1 or
  • override ref-fragment-path-delimiters by passing -rpd "/." or similar (double check whether output is as expected)

unkish avatar Jul 15 '22 16:07 unkish

Thank you!

dagyu avatar Jul 16 '22 11:07 dagyu

Closing this as it's a duplicate of #1402. I had a fix for this but I think I want to revisit and solve it more definitively. Just clearing the decks so we can see what's what.

joelittlejohn avatar Jan 07 '23 11:01 joelittlejohn