use of org.jsonschema2pojo.exception.GenerationException in project jsonschema2pojo by joelittlejohn.
the class TypeUtil method resolveType.
public static JClass resolveType(JClassContainer _package, String typeDefinition) {
try {
FieldDeclaration fieldDeclaration = (FieldDeclaration) JavaParser.parseBodyDeclaration(typeDefinition + " foo;");
ClassOrInterfaceType c = (ClassOrInterfaceType) ((ReferenceType) fieldDeclaration.getType()).getType();
return buildClass(_package, c, 0);
} catch (ParseException e) {
throw new GenerationException("Couldn't parse type: " + typeDefinition, e);
}
}
use of org.jsonschema2pojo.exception.GenerationException in project jsonschema2pojo by joelittlejohn.
the class SerializableHelper method addSerializableSupport.
public static void addSerializableSupport(JDefinedClass jclass) {
jclass._implements(Serializable.class);
try {
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
processDefinedClassForSerializableSupport(jclass, dataOutputStream);
dataOutputStream.flush();
final MessageDigest digest = MessageDigest.getInstance("SHA");
final byte[] digestBytes = digest.digest(byteArrayOutputStream.toByteArray());
long serialVersionUID = 0L;
for (int i = Math.min(digestBytes.length, 8) - 1; i >= 0; i--) {
serialVersionUID = serialVersionUID << 8 | digestBytes[i] & 0xff;
}
JFieldVar serialUIDField = jclass.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, long.class, "serialVersionUID");
serialUIDField.init(JExpr.lit(serialVersionUID));
} catch (IOException exception) {
throw new GenerationException("IOException while generating serialversionUID field while adding serializable support to class: " + jclass.fullName(), exception);
} catch (NoSuchAlgorithmException exception) {
throw new GenerationException("SHA algorithm not found when trying to generate serialversionUID field while adding serializable support to class: " + jclass.fullName(), exception);
}
}
Aggregations