public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException { SerializeWriter out = serializer.getWriter(); if (object == null) { serializer.getWriter().writeNull(); return; } if (serializer.isEnabled(SerializerFeature.WriteEnumUsingToString)) { Enum<?> e = (Enum<?>) object; serializer.write(e.name()); } else { Enum<?> e = (Enum<?>) object; out.writeInt(e.ordinal()); } }
public final void write( JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException { SerializeWriter out = serializer.getWriter(); if (object == null) { if (out.isEnabled(SerializerFeature.WriteNullListAsEmpty)) { out.write("[]"); } else { out.writeNull(); } return; } short[] array = (short[]) object; out.write('['); for (int i = 0; i < array.length; ++i) { if (i != 0) { out.write(','); } out.writeInt(array[i]); } out.write(']'); }
@SuppressWarnings({"rawtypes", "unchecked"}) public void write(PBSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException { SerializeWriter out = serializer.getWriter(); if (fieldName == null) { if (object instanceof ConcurrentHashMap) { out.getCodedOutputStream().writeRawByte(com.jd.glowworm.asm.Type.MAP_ConcurrentHashMap); } else if (object instanceof LinkedHashMap) { out.getCodedOutputStream().writeRawByte(com.jd.glowworm.asm.Type.MAP_LinkedHash); } else if (object instanceof HashMap) { out.getCodedOutputStream().writeRawByte(com.jd.glowworm.asm.Type.MAP_HASH); } else { out.getCodedOutputStream().writeRawByte(com.jd.glowworm.asm.Type.Unknown); } } Map<?, ?> map = (Map<?, ?>) object; try { int tmpMapSize = map.size(); out.writeInt(tmpMapSize); Class<?> preClazz = null; ObjectSerializer preWriter = null; for (Map.Entry entry : map.entrySet()) { Object entryKey = entry.getKey(); Object value = entry.getValue(); // if (entryKey == null || entryKey instanceof String) if (entryKey instanceof String) { String key = (String) entryKey; StringSerializer.instance.write(serializer, key, null, null); } else { serializer.write(entryKey); } if (value == null) { out.writeNull(); continue; } Class<?> clazz = value.getClass(); if (clazz == preClazz) { preWriter.write(serializer, value, null, null); } else { preClazz = clazz; preWriter = serializer.getObjectWriter(clazz); String tmpClassName = preWriter.getClass().getName(); if (tmpClassName.startsWith(ASMSerializerFactory.GenClassName_prefix)) { out.getCodedOutputStream().writeRawByte(com.jd.glowworm.asm.Type.OBJECT); out.writeString(clazz.getName()); } preWriter.write(serializer, value, null, clazz); } } } catch (Exception ex) { ex.printStackTrace(); } }