Commit 2f38d516 by s_guodong

update

parent 5015430e
package com.ceb.gjjs.mda.config;
import com.brilliance.eibs.util.StringUtil;
import com.brilliance.mda.runtime.annotation.RelPath;
import com.ceb.gjjs.mda.util.ValidatorUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import javax.validation.constraints.Pattern;
import java.io.IOException;
import java.lang.reflect.Field;
import java.text.ParseException;
......@@ -31,17 +31,23 @@ public class MyDateDeSerialized extends JsonDeserializer {
}
declaredField.setAccessible(true);
if (StringUtil.isNotEmpty(source)) {
String msg = declaredField.getAnnotation(RelPath.class).message();
Pattern annotation = declaredField.getAnnotation(Pattern.class);
String format = declaredField.getAnnotation(JsonFormat.class).pattern();
if (format.length() != source.length()) {
ValidatorUtil.CHECK_ERR_MSG.set(StringUtil.isEmpty(msg) ? "时间格式不正确" : msg);
return null;
}
// if (format.length() != source.length()) {
// ValidatorUtil.CHECK_ERR_MSG.set(annotation.message());
// return null;
// }
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
try {
date = simpleDateFormat.parse(source);
} catch (ParseException e) {
ValidatorUtil.CHECK_ERR_MSG.set(StringUtil.isEmpty(msg) ? "时间格式不正确" : msg);
ValidatorUtil.CHECK_ERR_MSG.set(annotation.message());
return null;
}
String regexp = annotation.regexp();
boolean match = source.matches(regexp);
if (!match) {
ValidatorUtil.CHECK_ERR_MSG.set(annotation.message());
return null;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment