question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow schema title to be used as class name (new useTitleAsClassname config option)

See original GitHub issue

When having schemas where certain field names are repeated with different implementations the code currently generates unique class names such as Image__1, etc. I would like to have a configuration to use the title as class name instead.

So that

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "SchemaTest body",
  "description": "Use title as class name.",
  "type": "object",
  "properties": {
    "image": {
      "type": "object",
      "title": "MyImage"
    }
  }
}

would result in

public class SchemaTest {

    private MyImage image;

    public SchemaTest() {
    }

    public SchemaTest(MyImage image) {
        super();
        this.image = image;
    }

    public MyImage getImage() {
        return image;
    }
}
public class MyImage{
}

Thank you for your great library. I am using it successfully and really like the RuleFactory design.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
joelittlejohncommented, Sep 14, 2018

Happy to accept a PR for this, as long as it is behind a configuration option, say, useTitleAsClassname. The default must be false.

0reactions
jrehwaldtcommented, Sep 17, 2018

Thank you very much! It was fun working on this one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

json - How to change default OutputSchema.java class name ...
If you use this, the class name will be what you specified in the title attribute of your schema. https://github.com/joelittlejohn/ ...
Read more >
Jsonschema2Pojo Task
Attribute Description Required source The input JSON schema. Yes useTitleAsClassname When set the title is used as classname. No (default false ) inclusionLevel Default value NON_NULL...
Read more >
README.md - joelittlejohn/jsonschema2pojo - Sourcegraph
jsonschema2pojo generates a Java representation of your json schema. ... Whether to use the 'title' property of the schema to decide the class...
Read more >
https://raw.githubusercontent.com/joelittlejohn/js...
Changelog ## 1.1.2 * Use LinkedHashMap for additional properties, ... Allow schema title to be used as class name (new useTitleAsClassname config option) ......
Read more >
Generate Java Classes using JSON (text) - Docker Hub
Available options are: off, error, warn, info, debug, trace Default: info -ut, --use-title-as-classname, When set class names are generated from title ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found