Comments (6)
From [email protected] on April 20, 2011 10:45:43
Discussion on this:
http://groups.google.com/group/jsonschema2pojo-users/browse_thread/thread/4ae73b8ee6c64060
from jsonschema2pojo.
From [email protected] on December 01, 2012 05:34:12
As a quick and dirty fix for this [I am assuming my schema locations a filenames and the filename is alphabets plus underscore (_) only and is followed by .json; but one can do some thing more sophisticated in the same vein):
--- a/jsonschema2pojo-core/src/main/java/com/googlecode/jsonschema2pojo/rules/JsonSchemaRule.java
+++ b/jsonschema2pojo-core/src/main/java/com/googlecode/jsonschema2pojo/rules/JsonSchemaRule.java
@@ -57,13 +57,17 @@ public class JsonSchemaRule implements SchemaRule<JClassContainer, JType> {
if (schemaNode.has("$ref")) {
schema = ruleFactory.getSchemaStore().create(schema, schemaNode.get("$ref").asText());
+String[] parts = schemaNode.get("$ref").asText().split("[^A-Za-z_]");
+String guessedName = parts[parts.length - 2];
schemaNode = schema.getContent();
if (schema.isGenerated()) {
return schema.getJavaType();
}
-
return apply(nodeName, schemaNode, generatableType, schema);
-
return apply(guessedName, schemaNode, generatableType, schema); }
from jsonschema2pojo.
From [email protected] on December 01, 2012 05:35:32
On a related note - worth raising a separate issue I would think; I don't want a $extends $ref to generate a class named XXXParent either, for that my other quick and dirty fix:
diff --git a/jsonschema2pojo-core/src/main/java/com/googlecode/jsonschema2pojo/rules/ObjectRule.java b/jsonschema2pojo-core/src/main/java/com/googlecode/jsonschema2pojo/rules/ObjectRule.java
index 3373a69..790f1b3 100644
--- a/jsonschema2pojo-core/src/main/java/com/googlecode/jsonschema2pojo/rules/ObjectRule.java
+++ b/jsonschema2pojo-core/src/main/java/com/googlecode/jsonschema2pojo/rules/ObjectRule.java
@@ -183,7 +183,10 @@ public class ObjectRule implements SchemaRule<JPackage, JType> {
private JType getSuperType(String nodeName, JsonNode node, JClassContainer jClassContainer, Schema schema) {
JType superType = jClassContainer.owner().ref(Object.class);
if (node.has("extends")) {
-
superType = ruleFactory.getSchemaRule().apply(nodeName + "Parent", node.get("extends"), jClassContainer, schema);
-
String[] parts = node.get("extends").get("$ref").asText().split("[^A-Za-z_]");
-
String guessedName = parts[parts.length - 2];
-
}
superType = ruleFactory.getSchemaRule().apply(guessedName, node.get("extends"), jClassContainer, schema); } return superType;
from jsonschema2pojo.
From [email protected] on December 01, 2012 06:12:09
One could come up with a more sophisticated URI to java class name conversion mechanism:
- first don't assume a flat packaging but mimic the relative URI structures of the schemas
2)SomeFile ==> SomeFile
SomeFile.json => SomeFile_json
SomeFile.X.json => SomeFile_X_json
Some_File.json => Some__File_json <= basically _ is escaped
3)Of course a simpler means would be to use a property (e.g. javaType) in the schema file (if it exists) as the POJO name. (while this is documented in the extentions - it doesn't work as expected
from jsonschema2pojo.
From [email protected] on December 01, 2012 18:33:44
@tseringshrestha I would think that the javaType property could allow you to workaround your problems. What problem did you have with it?
from jsonschema2pojo.
Resolving this as a dupe of #164 as there's a better, cleaner, description of the problem there.
from jsonschema2pojo.
Related Issues (20)
- Empty <p> tag
- Missing @param and @return tags for getter and setter methods
- How to create a simple pojo class with map attribute, not able to find any example. HOT 3
- Unable to generate javax.validation.constraints.DecimalMin and DecimalMax for type number HOT 2
- Inabily to refer to other POJO HOT 7
- versie 1.2.1: setting <useJakartaValidation>true</useJakartaValidation> stil generates import javax.annotation.Generated; HOT 1
- Unable to generate from schema due to "Path not present" HOT 5
- Add canonical setter for additionalProperties
- Task 'generateJsonSchema2Pojo' fails after upgrading to Android Gradle Plugin 8.2.2 / Gradle 8.2 HOT 4
- Builder methods return type is missing generics typed
- Multiple jsonschema to individual packages
- Can't get fileFilter working with gradle plugin HOT 2
- cli option --datetime-class 'java.sql.Time' does not work . defaults to string. HOT 1
- Gradle plugin: ability to set the sourceset to which generated files are added HOT 1
- how to generate jakarta imports in version 0.5.1 HOT 3
- How to declare one field as Map? HOT 2
- How to disable the set method for one field?
- Failed to use customRuleFactory HOT 1
- Spaces in field name causes Exception HOT 4
- When I click preview in website [https://www.jsonschema2pojo.org/], it doesn't work. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonschema2pojo.