Skip to content

Commit

Permalink
"ConversionException: Invalid format for date" in a query that takes
Browse files Browse the repository at this point in the history
date parameters #99
  • Loading branch information
RafaelChavesSenior committed Feb 13, 2016
1 parent 9547a11 commit 9ebb182
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ class JAXBSerializationGenerator extends BehaviorlessClassGenerator {
import java.util.function.Function;
import java.io.IOException;
import org.apache.commons.lang3.time.DateUtils;
import java.net.URI;
public class «entity.name»JAXBSerialization {
private static final String[] DATE_FORMATS = { "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd'T'HH:mm'Z'", "yyyy-MM-dd", "yyyy/MM/dd" };
public static Map<String, Object> toExternalRepresentation(«entity.name» toRender, URI instancesURI, boolean full) {
Map<String, Object> result = new LinkedHashMap<>();
boolean persisted = toRender.getId() != null;
Expand Down Expand Up @@ -94,9 +98,6 @@ class JAXBSerializationGenerator extends BehaviorlessClassGenerator {
public static void updateFromExternalRepresentation(«entity.name» toUpdate, Map<String, Object> external) {
Map<String, Object> values = (Map<String, Object>) external.get("values");
«IF (entity.properties.exists[type.name == 'Date'])»
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
«ENDIF»
«entity.properties.filter[property | !KirraHelper.isReadOnly(property, true)].map[ property |
val core = '''«setModelValue(property, "values", "toUpdate")»;'''
if (property.type.name == 'Date')
Expand Down Expand Up @@ -149,7 +150,7 @@ class JAXBSerializationGenerator extends BehaviorlessClassGenerator {
switch (typedElement.type.name) {
case 'Double' : '''Double.parseDouble(«expression».toString())'''
case 'Integer' : '''Long.parseLong(«expression».toString())'''
case 'Date' : '''dateFormat.parse((String) «expression»)'''
case 'Date' : '''DateUtils.parseDate((String) «expression», DATE_FORMATS)'''
default: if (typedElement.type.entity) convertIdToInternal(typedElement, expression) else '''(«typedElement.toJavaType(true)») «expression»'''
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class JAXRSResourceGenerator extends BehaviorlessClassGenerator {
import java.text.*;
import java.util.function.Function;
import java.io.IOException;
import org.apache.commons.lang3.time.DateUtils;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
Expand All @@ -58,6 +60,8 @@ class JAXRSResourceGenerator extends BehaviorlessClassGenerator {
@Path("entities/«entityFullName»/")
@Produces(MediaType.APPLICATION_JSON)
public class «entity.name»Resource {
private static final String[] DATE_FORMATS = { "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd'T'HH:mm'Z'", "yyyy-MM-dd", "yyyy/MM/dd" };
@Context
UriInfo uri;
Expand Down Expand Up @@ -253,9 +257,6 @@ class JAXRSResourceGenerator extends BehaviorlessClassGenerator {

def CharSequence generateArgumentMatching(Operation operation) {
'''
«IF (operation.parameters.exists[type.name == 'Date'])»
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
«ENDIF»
«operation.parameters.map[
'''
«it.type.toJavaType» «it.name»«IF !it.required» = null«ENDIF»;
Expand Down Expand Up @@ -300,7 +301,7 @@ class JAXRSResourceGenerator extends BehaviorlessClassGenerator {
switch (typedElement.type.name) {
case 'Double' : '''Double.parseDouble(«expression».toString())'''
case 'Integer' : '''Long.parseLong(«expression».toString())'''
case 'Date' : '''dateFormat.parse((String) «expression»)'''
case 'Date' : '''DateUtils.parseDate((String) «expression», DATE_FORMATS)'''
default: if (typedElement.type.entity) convertIdToInternal(typedElement, expression) else '''(«typedElement.toJavaType(true)») «expression»'''
}
}
Expand Down

0 comments on commit 9ebb182

Please sign in to comment.