Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/develop' into robolectric
Browse files Browse the repository at this point in the history
# Conflicts:
#	batching-gson/build.gradle
  • Loading branch information
anirudhramanan committed Jan 20, 2017
2 parents 378b81c + 3630e75 commit c3e5742
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 336 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@

package com.flipkart.batching.core;

import com.flipkart.batching.core.exception.DeserializeException;
import com.flipkart.batching.core.exception.SerializeException;

import java.io.IOException;
import java.util.Collection;

/**
Expand All @@ -45,24 +44,24 @@ public interface SerializationStrategy<E extends Data, T extends Batch> {
*
* @param data {@link Data} object to be serialized
* @return byte array
* @throws SerializeException
* @throws IOException
*/
byte[] serializeData(E data) throws SerializeException;
byte[] serializeData(E data) throws IOException;

byte[] serializeCollection(Collection<E> data) throws SerializeException;
byte[] serializeCollection(Collection<E> data) throws IOException;

byte[] serializeBatch(T batch) throws SerializeException;
byte[] serializeBatch(T batch) throws IOException;

/**
* This method deserialize the provided byte array of data.
*
* @param data byte[] type data
* @return {@link Object} type data
* @throws DeserializeException
* @throws IOException
*/
E deserializeData(byte[] data) throws DeserializeException;
E deserializeData(byte[] data) throws IOException;

Collection<E> deserializeCollection(byte[] data) throws DeserializeException;
Collection<E> deserializeCollection(byte[] data) throws IOException;

T deserializeBatch(byte[] data) throws DeserializeException;
T deserializeBatch(byte[] data) throws IOException;
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 1 addition & 2 deletions batching-gson/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.android.support:support-annotations:25.1.0'
compile 'com.github.flipkart-incubator.batchman:batching-core:1.3.2'

compile project(':batching-core')
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.2.2'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import com.flipkart.batching.core.batch.TimeBatch;
import com.flipkart.batching.core.data.EventData;
import com.flipkart.batching.core.data.TagData;
import com.flipkart.batching.core.exception.DeserializeException;
import com.flipkart.batching.core.exception.SerializeException;
import com.flipkart.batching.gson.adapters.BatchImplTypeAdapter;
import com.flipkart.batching.gson.adapters.BatchingTypeAdapterFactory;
import com.flipkart.batching.gson.adapters.BatchingTypeAdapters;
Expand All @@ -50,11 +48,13 @@
import com.flipkart.batching.gson.adapters.data.TagDataTypeAdapter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapter;
import com.google.gson.internal.ObjectConstructor;
import com.google.gson.stream.JsonReader;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;

Expand Down Expand Up @@ -141,15 +141,13 @@ public void build() {
gsonBuilder.registerTypeAdapterFactory(getDataRuntimeTypeAdapter());
gsonBuilder.registerTypeAdapterFactory(getBatchRuntimeTypeAdapter());
gsonBuilder.registerTypeAdapterFactory(new BatchingTypeAdapterFactory());

TagDataTypeAdapter tagDataTypeAdapter = new TagDataTypeAdapter();
registerDataSubTypeAdapters(EventData.class, new EventDataTypeAdapter());
registerDataSubTypeAdapters(TagData.class, tagDataTypeAdapter);
registerBatchSubTypeAdapters(TagBatch.class, new TagBatchTypeAdapter<>(tagDataTypeAdapter));
registerDataSubTypeAdapters(TagData.class, new TagDataTypeAdapter());

gson = gsonBuilder.create();

//Register Built in types
registerBatchSubTypeAdapters(TagBatch.class, new TagBatchTypeAdapter<>(getDataTypeAdapter()));
registerBatchSubTypeAdapters(SizeBatch.class, new SizeBatchTypeAdapter<>(getDataTypeAdapter()));
registerBatchSubTypeAdapters(BatchImpl.class, new BatchImplTypeAdapter<>(getDataTypeAdapter()));
registerBatchSubTypeAdapters(SizeTimeBatch.class, new SizeTimeBatchTypeAdapter<>(getDataTypeAdapter()));
Expand All @@ -163,62 +161,44 @@ private void checkIfBuildCalled() {
}

@Override
public byte[] serializeData(E data) throws SerializeException {
public byte[] serializeData(E data) throws IOException {
checkIfBuildCalled();
try {
return getDataTypeAdapter().toJson(data).getBytes();
} catch (JsonParseException e) {
throw new SerializeException(e);
}
StringWriter stringWriter = new StringWriter();
getDataTypeAdapter().toJson(stringWriter, data);
return stringWriter.toString().getBytes();
}

@Override
public byte[] serializeCollection(Collection<E> data) throws SerializeException {
public byte[] serializeCollection(Collection<E> data) throws IOException {
checkIfBuildCalled();
try {
return getCollectionTypeAdapter().toJson(data).getBytes();
} catch (JsonParseException e) {
throw new SerializeException(e);
}
StringWriter stringWriter = new StringWriter();
getCollectionTypeAdapter().toJson(stringWriter, data);
return stringWriter.toString().getBytes();
}

@Override
public byte[] serializeBatch(T batch) throws SerializeException {
public byte[] serializeBatch(T batch) throws IOException {
checkIfBuildCalled();
try {
return getBatchTypeAdapter().toJson(batch).getBytes();
} catch (JsonParseException e) {
throw new SerializeException(e);
}
StringWriter stringWriter = new StringWriter();
getBatchTypeAdapter().toJson(stringWriter, batch);
return stringWriter.toString().getBytes();
}

@Override
public E deserializeData(byte[] data) throws DeserializeException {
public E deserializeData(byte[] data) throws IOException {
checkIfBuildCalled();
try {
return getDataTypeAdapter().fromJson(new String(data));
} catch (IOException e) {
throw new DeserializeException(e);
}
return getDataTypeAdapter().read(new JsonReader(new StringReader(new String(data))));
}

@Override
public Collection<E> deserializeCollection(byte[] data) throws DeserializeException {
public Collection<E> deserializeCollection(byte[] data) throws IOException {
checkIfBuildCalled();
try {
return getCollectionTypeAdapter().fromJson(new String(data));
} catch (IOException e) {
throw new DeserializeException(e);
}
return getCollectionTypeAdapter().read(new JsonReader(new StringReader(new String(data))));
}

@Override
public T deserializeBatch(byte[] data) throws DeserializeException {
public T deserializeBatch(byte[] data) throws IOException {
checkIfBuildCalled();
try {
return getBatchTypeAdapter().fromJson(new String(data));
} catch (IOException e) {
throw new DeserializeException(e);
}
return getBatchTypeAdapter().read(new JsonReader(new StringReader(new String(data))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package com.flipkart.batching.gson.adapters.batch;

import com.flipkart.batching.core.BatchImpl;
import com.flipkart.batching.core.Data;
import com.flipkart.batching.core.DataCollection;
import com.flipkart.batching.core.batch.TagBatch;
import com.flipkart.batching.core.data.Tag;
Expand All @@ -40,8 +41,8 @@ public final class TagBatchTypeAdapter<T extends TagData> extends TypeAdapter<Ta
private final TypeAdapter<DataCollection<T>> typeAdapter;
private final TypeAdapter<Tag> tagTypeAdapter;

public TagBatchTypeAdapter(TypeAdapter<T> typeAdapter) {
this.typeAdapter = new DataCollectionTypeAdapter<>(typeAdapter);
public <E extends Data> TagBatchTypeAdapter(TypeAdapter<E> typeAdapter) {
this.typeAdapter = new DataCollectionTypeAdapter(typeAdapter);
this.tagTypeAdapter = new TagTypeAdapter();
}

Expand Down
Loading

0 comments on commit c3e5742

Please sign in to comment.