@Provides @Singleton @Inject RobotSerializer provideRobotSerializer() { NavigableMap<ProtocolVersion, Gson> gsons = Maps.newTreeMap(); Gson gsonForPostV2 = new GsonFactory().create(); gsons.put(ProtocolVersion.V2_2, gsonForPostV2); // Remove lines below if we want to stop support for <0.22 gsons.put(ProtocolVersion.V2_1, gsonForPostV2); GsonFactory factoryForV2 = new GsonFactory(); ElementGsonAdaptorV2 elementGsonAdaptorV2 = new ElementGsonAdaptorV2(); factoryForV2.registerTypeAdapter(Element.class, elementGsonAdaptorV2); factoryForV2.registerTypeAdapter(Attachment.class, elementGsonAdaptorV2); gsons.put(ProtocolVersion.V2, factoryForV2.create()); return new RobotSerializer(gsons, ProtocolVersion.DEFAULT); }
bundle.addEvent(event3); bundle.setWaveletData(waveletData); String json = new GsonFactory().create().toJson(bundle);
/** * Creates a {@link Gson} instance, with additional type adapters for these * types: * <ul> * <li>{@link EventMessageBundle}</li> * <li>{@link OperationRequest}</li> * <li>{@link Element}</li> * </ul> * * @return an instance of {@link Gson} with pre-registered type adapters. */ public Gson create() { return create(""); }
/** * Registers this {@link ElementGsonAdaptorV2} with the given * {@link GsonFactory}. * @param factory {@link GsonFactory} to register the type adapters with * @return the given {@link GsonFactory} with the registered adapters */ public static GsonFactory registerTypeAdapters(GsonFactory factory) { ElementGsonAdaptorV2 elementGsonAdaptorV2 = new ElementGsonAdaptorV2(); factory.registerTypeAdapter(Element.class, elementGsonAdaptorV2); factory.registerTypeAdapter(Attachment.class, elementGsonAdaptorV2); return factory; } }
bundle.addEvent(event3); bundle.setWaveletData(waveletData); String json = new GsonFactory().create().toJson(bundle);