static boolean isNonStringMapSchema(Schema s) { if (s != null && s.getType() == Schema.Type.ARRAY) { Class c = getClassProp(s, CLASS_PROP); if (c != null && Map.class.isAssignableFrom (c)) return true; } return false; }
static boolean isNonStringMapSchema(Schema s) { if (s != null && s.getType() == Schema.Type.ARRAY) { Class c = getClassProp(s, CLASS_PROP); if (c != null && Map.class.isAssignableFrom (c)) return true; } return false; }
@Override protected Object readBytes(Object old, Schema s, Decoder in) throws IOException { ByteBuffer bytes = in.readBytes(null); Class<?> c = ReflectData.getClassProp(s, SpecificData.CLASS_PROP); if (c != null && c.isArray()) { byte[] result = new byte[bytes.remaining()]; bytes.get(result); return result; } else { return bytes; } }
@Override protected Object readBytes(Object old, Schema s, Decoder in) throws IOException { ByteBuffer bytes = in.readBytes(null); Class<?> c = ReflectData.getClassProp(s, SpecificData.CLASS_PROP); if (c != null && c.isArray()) { byte[] result = new byte[bytes.remaining()]; bytes.get(result); return result; } else { return bytes; } }
Class collectionClass = getClassProp(schema, CLASS_PROP); if (collectionClass != null) return collectionClass; Class stringClass = getClassProp(schema, CLASS_PROP); if (stringClass != null) return stringClass;
Class collectionClass = getClassProp(schema, CLASS_PROP); if (collectionClass != null) return collectionClass; Class stringClass = getClassProp(schema, CLASS_PROP); if (stringClass != null) return stringClass;
@Override protected Object newArray(Object old, int size, Schema schema) { Class<?> collectionClass = ReflectData.getClassProp(schema, SpecificData.CLASS_PROP); Class<?> elementClass = ReflectData.getClassProp(schema, SpecificData.ELEMENT_PROP);
@Override protected Object newArray(Object old, int size, Schema schema) { Class<?> collectionClass = ReflectData.getClassProp(schema, SpecificData.CLASS_PROP); Class<?> elementClass = ReflectData.getClassProp(schema, SpecificData.ELEMENT_PROP);
static boolean isNonStringMapSchema(Schema s) { if (s != null && s.getType() == Schema.Type.ARRAY) { Class c = getClassProp(s, CLASS_PROP); if (c != null && Map.class.isAssignableFrom (c)) return true; } return false; }
@Override protected Object readBytes(Object old, Schema s, Decoder in) throws IOException { ByteBuffer bytes = in.readBytes(null); Class<?> c = ReflectData.getClassProp(s, SpecificData.CLASS_PROP); if (c != null && c.isArray()) { byte[] result = new byte[bytes.remaining()]; bytes.get(result); return result; } else { return bytes; } }
@Override protected Object readBytes(Object old, Schema s, Decoder in) throws IOException { ByteBuffer bytes = in.readBytes(null); Class<?> c = ReflectData.getClassProp(s, SpecificData.CLASS_PROP); if (c != null && c.isArray()) { byte[] result = new byte[bytes.remaining()]; bytes.get(result); return result; } else { return bytes; } }
@Override @SuppressWarnings(value="unchecked") protected Object readString(Object old, Schema s, Decoder in) throws IOException { String value = (String)readString(null, in); Class c = ReflectData.getClassProp(s, ReflectData.CLASS_PROP); if (c != null) // Stringable annotated class try { // use String-arg ctor return c.getConstructor(String.class).newInstance(value); } catch (NoSuchMethodException e) { throw new AvroRuntimeException(e); } catch (InstantiationException e) { throw new AvroRuntimeException(e); } catch (IllegalAccessException e) { throw new AvroRuntimeException(e); } catch (InvocationTargetException e) { throw new AvroRuntimeException(e); } return value; }
@Override @SuppressWarnings(value="unchecked") protected Object readString(Object old, Schema s, Decoder in) throws IOException { String value = (String)readString(null, in); Class c = ReflectData.getClassProp(s, ReflectData.CLASS_PROP); if (c != null) // Stringable annotated class try { // use String-arg ctor return c.getConstructor(String.class).newInstance(value); } catch (NoSuchMethodException e) { throw new AvroRuntimeException(e); } catch (InstantiationException e) { throw new AvroRuntimeException(e); } catch (IllegalAccessException e) { throw new AvroRuntimeException(e); } catch (InvocationTargetException e) { throw new AvroRuntimeException(e); } return value; }
@Override @SuppressWarnings(value="unchecked") protected Object newArray(Object old, int size, Schema schema) { ReflectData data = ReflectData.get(); Class collectionClass = ReflectData.getClassProp(schema, ReflectData.CLASS_PROP); if (collectionClass != null) { if (old instanceof Collection) { ((Collection)old).clear(); return old; } if (collectionClass.isAssignableFrom(ArrayList.class)) return new ArrayList(); return newInstance(collectionClass); } Class elementClass = ReflectData.getClassProp(schema, ReflectData.ELEMENT_PROP); if (elementClass == null) elementClass = data.getClass(schema.getElementType()); return Array.newInstance(elementClass, size); }
@Override @SuppressWarnings(value="unchecked") protected Object newArray(Object old, int size, Schema schema) { ReflectData data = ReflectData.get(); Class collectionClass = ReflectData.getClassProp(schema, ReflectData.CLASS_PROP); if (collectionClass != null) { if (old instanceof Collection) { ((Collection)old).clear(); return old; } if (collectionClass.isAssignableFrom(ArrayList.class)) return new ArrayList(); return newInstance(collectionClass, schema); } Class elementClass = ReflectData.getClassProp(schema, ReflectData.ELEMENT_PROP); if (elementClass == null) elementClass = data.getClass(schema.getElementType()); return Array.newInstance(elementClass, size); }
@Override public Class getClass(Schema schema) { switch (schema.getType()) { case ARRAY: Class collectionClass = getClassProp(schema, CLASS_PROP); if (collectionClass != null) return collectionClass; return java.lang.reflect.Array.newInstance(getClass(schema.getElementType()),0).getClass(); case STRING: return String.class; case BYTES: return BYTES_CLASS; case INT: if (Short.class.getName().equals(schema.getProp(CLASS_PROP))) return Short.TYPE; default: return super.getClass(schema); } }
@Override public Class getClass(Schema schema) { switch (schema.getType()) { case ARRAY: Class collectionClass = getClassProp(schema, CLASS_PROP); if (collectionClass != null) return collectionClass; Class elementClass = getClass(schema.getElementType()); if(elementClass.isPrimitive()) { // avoid expensive translation to array type when primitive return ARRAY_CLASSES.get(elementClass); } else { return java.lang.reflect.Array.newInstance(elementClass, 0).getClass(); } case STRING: Class stringClass = getClassProp(schema, CLASS_PROP); if (stringClass != null) return stringClass; return String.class; case BYTES: return BYTES_CLASS; case INT: String intClass = schema.getProp(CLASS_PROP); if (Byte.class.getName().equals(intClass)) return Byte.TYPE; if (Short.class.getName().equals(intClass)) return Short.TYPE; if (Character.class.getName().equals(intClass)) return Character.TYPE; default: return super.getClass(schema); } }
@Override public Class getClass(Schema schema) { switch (schema.getType()) { case ARRAY: Class collectionClass = getClassProp(schema, CLASS_PROP); if (collectionClass != null) return collectionClass; return java.lang.reflect.Array.newInstance(getClass(schema.getElementType()),0).getClass(); case STRING: return String.class; case BYTES: return BYTES_CLASS; case INT: if (Short.class.getName().equals(schema.getProp(CLASS_PROP))) return Short.TYPE; default: return super.getClass(schema); } }
@Override protected Object newArray(Object old, int size, Schema schema) { Class<?> collectionClass = ReflectData.getClassProp(schema, SpecificData.CLASS_PROP); Class<?> elementClass = ReflectData.getClassProp(schema, SpecificData.ELEMENT_PROP); if (collectionClass == null && elementClass == null) return super.newArray(old, size, schema); // use specific/generic if (collectionClass != null && !collectionClass.isArray()) { if (old instanceof Collection) { ((Collection<?>)old).clear(); return old; } if (collectionClass.isAssignableFrom(ArrayList.class)) return new ArrayList<Object>(); return SpecificData.newInstance(collectionClass, schema); } if (elementClass == null) { elementClass = collectionClass.getComponentType(); } if (elementClass == null) { ReflectData data = (ReflectData)getData(); elementClass = data.getClass(schema.getElementType()); } return Array.newInstance(elementClass, size); }
@Override protected Object newArray(Object old, int size, Schema schema) { Class<?> collectionClass = ReflectData.getClassProp(schema, SpecificData.CLASS_PROP); Class<?> elementClass = ReflectData.getClassProp(schema, SpecificData.ELEMENT_PROP);