@Override public Serializable normalize(Object value) throws PropertyConversionException { if (isNormalized(value)) { return (Serializable) value; } if (value.getClass() == Date.class) { Calendar cal = Calendar.getInstance(); cal.setTime((Date) value); return cal; } if (value instanceof String) { String string = (String) value; if (string.length() == 0) { return null; } return (Calendar) field.getType().decode(value.toString()); } throw new PropertyConversionException(value.getClass(), Calendar.class); }
@Override public Object getDefaultValue() { return type.decode(defaultValue); }
@Override public Object getDefaultValue() { return type.decode(defaultValue); }
@Override public Object decode(String string) { if (StringUtils.isBlank(string)) { return null; } String[] split = string.split(DEFAULT_VALUE_SEPARATOR); List<Object> decoded = new ArrayList<>(split.length); Class<?> klass = null; for (String s : split) { Object o = type.decode(s); if (klass == null && o != null) { klass = o.getClass(); } decoded.add(o); } if (klass == null) { klass = Object.class; } // turn the list into a properly-typed array for the elements Object[] array = (Object[]) Array.newInstance(klass, decoded.size()); return decoded.toArray(array); }
public Map<String, Serializable> convert(SearchHit hit) { Map<String, Serializable> row = new HashMap<>(emptyRow); hit.getSourceAsMap().forEach((name, value) -> { // type conversion if (value instanceof String) { Type type = selectFieldsAndTypes.get(name); if (type instanceof DateType) { // convert back to calendar value = type.decode(((String) value)); } } row.put(name, (Serializable) value); }); if (selectFieldsAndTypes.containsKey(NXQL.ECM_FULLTEXT_SCORE)) { row.put(NXQL.ECM_FULLTEXT_SCORE, (double) hit.getScore()); } return row; }
private Object getPropertyValue(Type type, JsonNode jn) throws IOException { Object value; if (jn.isNull()) { value = null; } else if (type instanceof BooleanType) { value = jn.asBoolean(); } else if (type instanceof LongType) { value = jn.asLong(); } else if (type instanceof DoubleType) { value = jn.asDouble(); } else if (type instanceof IntegerType) { value = jn.asInt(); } else if (type instanceof BinaryType) { value = jn.binaryValue(); } else { value = type.decode(jn.asText()); } return value; }
return type.decode(element.getText()); } else if (type.isListType()) { ListType ltype = (ListType) type;
Element element, Type type) { if (type.isSimpleType()) { return type.decode(element.getText()); } else if (type.isListType()) { ListType ltype = (ListType) type;