Skip to content

Commit

Permalink
fixed crash on properties which type is interface type (e.g. java.tim…
Browse files Browse the repository at this point in the history
…e.LocalDateTime#chronology)
  • Loading branch information
vojtechhabarta committed Oct 29, 2015
1 parent 8ad4d61 commit cdd448d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sample-gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ generateTypeScript {
'cz.habarta.typescript.generator.sample.Person'
]
jsonLibrary = 'jackson2'
namespace = 'Rest';
namespace = 'GradleSample';
// module = 'my-module'
// declarePropertiesAsOptional = false
// removeTypeNameSuffix = 'Json'
Expand Down
2 changes: 2 additions & 0 deletions sample-maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
<classes>
<class>cz.habarta.typescript.generator.sample.Person</class>
</classes>
<jsonLibrary>jackson2</jsonLibrary>
<outputFile>target/sample.d.ts</outputFile>
<namespace>MavenSample</namespace>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public ClassWithUsage(Class<?> beanClass, String usedInProperty, Class<?> usedIn
}

public String usage() {
return usedInClass.getSimpleName() + "." + usedInProperty;
return (usedInClass != null ? (usedInClass.getSimpleName() + ".") : "") + usedInProperty;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected BeanModel parseBean(ClassWithUsage classWithUsage) {
for (BeanPropertyWriter beanPropertyWriter : beanHelper.getProperties()) {
if (!isParentProperty(beanPropertyWriter.getName(), classWithUsage.beanClass)) {
Type propertyType = beanPropertyWriter.getGenericPropertyType();
if (propertyType.equals(JsonNode.class)) {
if (propertyType == JsonNode.class) {
propertyType = Object.class;
}
properties.add(processTypeAndCreateProperty(beanPropertyWriter.getName(), propertyType, classWithUsage.beanClass));
Expand All @@ -42,15 +42,15 @@ protected BeanModel parseBean(ClassWithUsage classWithUsage) {
addBeanToQueue(new ClassWithUsage(type.value(), "<subClass>", classWithUsage.beanClass));
}
}
final Class<?> superclass = classWithUsage.beanClass.getSuperclass().equals(Object.class) ? null : classWithUsage.beanClass.getSuperclass();
final Class<?> superclass = classWithUsage.beanClass.getSuperclass() == Object.class ? null : classWithUsage.beanClass.getSuperclass();
if (superclass != null) {
addBeanToQueue(new ClassWithUsage(superclass, "<superClass>", classWithUsage.beanClass));
}
return new BeanModel(classWithUsage.beanClass, superclass, properties);
}

private boolean isParentProperty(String property, Class<?> cls) {
if (cls.getSuperclass().equals(Object.class)) {
if (cls.getSuperclass() == Object.class) {
return false;
} else {
final BeanHelper beanHelper = getBeanHelper(cls.getSuperclass());
Expand All @@ -66,6 +66,9 @@ private boolean isParentProperty(String property, Class<?> cls) {
}

private BeanHelper getBeanHelper(Class<?> beanClass) {
if (beanClass == null) {
return null;
}
try {
final SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
final JavaType simpleType = objectMapper.constructType(beanClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected BeanModel parseBean(ClassWithUsage classWithUsage) {
for (BeanPropertyWriter beanPropertyWriter : beanHelper.getProperties()) {
if (!isParentProperty(beanPropertyWriter.getName(), classWithUsage.beanClass)) {
Type propertyType = beanPropertyWriter.getGenericPropertyType();
if (propertyType.equals(JsonNode.class)) {
if (propertyType == JsonNode.class) {
propertyType = Object.class;
}
properties.add(processTypeAndCreateProperty(beanPropertyWriter.getName(), propertyType, classWithUsage.beanClass));
Expand All @@ -41,15 +41,15 @@ protected BeanModel parseBean(ClassWithUsage classWithUsage) {
addBeanToQueue(new ClassWithUsage(type.value(), "<subClass>", classWithUsage.beanClass));
}
}
final Class<?> superclass = classWithUsage.beanClass.getSuperclass().equals(Object.class) ? null : classWithUsage.beanClass.getSuperclass();
final Class<?> superclass = classWithUsage.beanClass.getSuperclass() == Object.class ? null : classWithUsage.beanClass.getSuperclass();
if (superclass != null) {
addBeanToQueue(new ClassWithUsage(superclass, "<superClass>", classWithUsage.beanClass));
}
return new BeanModel(classWithUsage.beanClass, superclass, properties);
}

private boolean isParentProperty(String property, Class<?> cls) {
if (cls.getSuperclass().equals(Object.class)) {
if (cls.getSuperclass() == Object.class) {
return false;
} else {
final BeanHelper beanHelper = getBeanHelper(cls.getSuperclass());
Expand All @@ -65,6 +65,9 @@ private boolean isParentProperty(String property, Class<?> cls) {
}

private BeanHelper getBeanHelper(Class<?> beanClass) {
if (beanClass == null) {
return null;
}
try {
final DefaultSerializerProvider.Impl serializerProvider1 = (DefaultSerializerProvider.Impl) objectMapper.getSerializerProvider();
final DefaultSerializerProvider.Impl serializerProvider2 = serializerProvider1.createInstance(objectMapper.getSerializationConfig(), objectMapper.getSerializerFactory());
Expand Down

0 comments on commit cdd448d

Please sign in to comment.