in cassandrawriter/src/main/java/com/alibaba/datax/plugin/writer/cassandrawriter/CassandraWriterHelper.java [145:245]
public static Object parseFromJson(Object jsonObject,DataType type) throws Exception {
if( jsonObject == null ) return null;
switch (type.getName()) {
case ASCII:
case TEXT:
case VARCHAR:
case BOOLEAN:
case TIME:
return jsonObject;
case TINYINT:
return ((Number)jsonObject).byteValue();
case SMALLINT:
return ((Number)jsonObject).shortValue();
case INT:
return ((Number)jsonObject).intValue();
case BIGINT:
return ((Number)jsonObject).longValue();
case VARINT:
return new BigInteger(jsonObject.toString());
case FLOAT:
return ((Number)jsonObject).floatValue();
case DOUBLE:
return ((Number)jsonObject).doubleValue();
case DECIMAL:
return new BigDecimal(jsonObject.toString());
case BLOB:
return ByteBuffer.wrap(Base64.decodeBase64((String)jsonObject));
case DATE:
return LocalDate.fromMillisSinceEpoch(((Number)jsonObject).longValue());
case TIMESTAMP:
return new Date(((Number)jsonObject).longValue());
case DURATION:
return Duration.from(jsonObject.toString());
case UUID:
case TIMEUUID:
return UUID.fromString(jsonObject.toString());
case INET:
return InetAddress.getByName((String)jsonObject);
case LIST:
List l = new ArrayList();
for( Object o : (JSONArray)jsonObject ) {
l.add(parseFromJson(o,type.getTypeArguments().get(0)));
}
return l;
case MAP: {
Map m = new HashMap();
for (Map.Entry e : ((JSONObject)jsonObject).entrySet()) {
Object k = parseFromString((String) e.getKey(), type.getTypeArguments().get(0));
Object v = parseFromJson(e.getValue(), type.getTypeArguments().get(1));
m.put(k,v);
}
return m;
}
case SET:
Set s = new HashSet();
for( Object o : (JSONArray)jsonObject ) {
s.add(parseFromJson(o,type.getTypeArguments().get(0)));
}
return s;
case TUPLE: {
TupleValue t = ((TupleType) type).newValue();
int j = 0;
for (Object e : (JSONArray)jsonObject) {
DataType eleType = ((TupleType) type).getComponentTypes().get(j);
t.set(j, parseFromJson(e, eleType), registry.codecFor(eleType).getJavaType());
j++;
}
return t;
}
case UDT: {
UDTValue t = ((UserType) type).newValue();
UserType userType = t.getType();
for (Map.Entry e : ((JSONObject)jsonObject).entrySet()) {
DataType eleType = userType.getFieldType((String)e.getKey());
t.set((String)e.getKey(), parseFromJson(e.getValue(), eleType), registry.codecFor(eleType).getJavaType());
}
return t;
}
}
return null;
}