public Value(JsonFormat ann) { this(ann.pattern(), ann.shape(), ann.locale(), ann.timezone(), Features.construct(ann), ann.lenient().asBoolean()); }
public Value(JsonFormat ann) { this(ann.pattern(), ann.shape(), ann.locale(), ann.timezone(), Features.construct(ann), ann.lenient().asBoolean()); }
public Value(JsonFormat ann) { this(ann.pattern(), ann.shape(), ann.locale(), ann.timezone(), Features.construct(ann), ann.lenient().asBoolean()); }
@Override public void setCell(Date o, Cell cell, Field field) { if (o != null) { String format = field.getAnnotation(JsonFormat.class).pattern(); cell.setCellValue(new SimpleDateFormat(format).format(o)); } }
@Override public Date parse(JsonParser parser, Field field) throws IOException { if (!isValid(parser)) { return null; } JsonFormat formatAnn = field.getAnnotation(JsonFormat.class); if (formatAnn == null) { throw new RuntimeException("JsonFormat with pattern needed for: " + field.getName()); } try { return new SimpleDateFormat(formatAnn.pattern(), Locale.getDefault()).parse(parser.getValueAsString()); } catch (ParseException e) { throw new RuntimeException("JsonFormat with pattern is wrong for: " + field.getName() + " pattern: " + formatAnn.pattern()); } } }
/** * First it checks is there any annotation class for parsing operations, * if it is, parses with given format, if there is a exception while * parsing with given format catches and tries with default values, * If there is no given format, tries with static values * * @param o Object from cell value * @param field Field from given pojo * @return Valid date after parsing with pattern */ @Override public Date parse(Object o, Field field) { if (!isValid(o)) { return null; } JsonFormat formatAnn = field.getAnnotation(JsonFormat.class); if (formatAnn == null) { throw new RuntimeException("JsonFormat with pattern needed for: " + field.getName()); } try { return new SimpleDateFormat(formatAnn.pattern(), Locale.getDefault()).parse(o.toString()); } catch (ParseException e) { throw new RuntimeException("JsonFormat with pattern is wrong for: " + field.getName() + " pattern: " + formatAnn.pattern()); } }
static CellProcessorAdaptor decideAdaptor(Field field) { String fieldType = field.getType().getSimpleName().toUpperCase(Locale.ENGLISH); // if it is enum convert name to ENUM if(field.getType().getGenericSuperclass() != null) { if (field.getType().getGenericSuperclass().toString().startsWith("java.lang.Enum")) { fieldType = "ENUM"; return Parsers.valueOf(fieldType).getParser(field.getType()); } } if(fieldType.equals("DATE")){ if(field.getAnnotation(JsonFormat.class) != null){ String format = field.getAnnotation(JsonFormat.class).pattern(); return new ParseDate(format); }else{ throw new RuntimeException("Date type must have SimpleDateFormat annotation with a valid format."); } }else{ return Parsers.valueOf(fieldType).getParser(); } } }
private void read(ReflectAnnotatedElement annotations) { if (annotations == null) { return; } JsonFormat format = annotations.getAnnotation(JsonFormat.class); if (format == null) { return; } if (format.shape() == JsonFormat.Shape.STRING) { asString = true; } else { return; } pattern = format.pattern(); if (pattern.isEmpty()) { pattern = null; } locale = format.locale(); }
public Value(JsonFormat ann) { this(ann.pattern(), ann.shape(), ann.locale(), ann.timezone()); }
public Value(JsonFormat ann) { this(ann.pattern(), ann.shape(), ann.locale(), ann.timezone()); }
public Value(JsonFormat ann) { this(ann.pattern(), ann.shape(), ann.locale(), ann.timezone()); }
public Value(JsonFormat ann) { this(ann.pattern(), ann.shape(), ann.locale(), ann.timezone()); }
public Value(JsonFormat ann) { this(ann.pattern(), ann.shape(), ann.locale(), ann.timezone()); }
public Value(JsonFormat ann) { this(ann.pattern(), ann.shape(), ann.locale(), ann.timezone()); }
public Value(JsonFormat ann) { this(ann.pattern(), ann.shape(), ann.locale(), ann.timezone(), Features.construct(ann)); }
/** * Add the common property parameters to the code builder. * * @param paramBuilder the code builder * @param property the information about the property */ protected final void buildCommonPropertyParameters( CodeBlock.Builder paramBuilder, PropertyInfo property ) { if ( property.getFormat().isPresent() ) { JsonFormat format = property.getFormat().get(); if ( !Strings.isNullOrEmpty( format.pattern() ) ) { paramBuilder.add( "\n.setPattern($S)", format.pattern() ); } paramBuilder.add( "\n.setShape($T.$L)", Shape.class, format.shape().name() ); if ( !Strings.isNullOrEmpty( format.locale() ) && !JsonFormat.DEFAULT_LOCALE.equals( format.locale() ) ) { logger.log( Type.WARN, "JsonFormat.locale is not supported by default" ); paramBuilder.add( "\n.setLocale($S)", format.locale() ); } } if ( property.getIgnoredProperties().isPresent() ) { for ( String ignoredProperty : property.getIgnoredProperties().get() ) { paramBuilder.add( "\n.addIgnoredProperty($S)", ignoredProperty ); } } }