Skip to content

Commit

Permalink
surfacelinename and surfacelinecode gson deserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
janvde committed Aug 29, 2017
1 parent 9033be0 commit 2bb9975
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class SurfaceAgency implements Parcelable {
private float frequency;
private float duration;
private DayFlags operatindDays;
private List<String> lineNames;
private List<String> lineCodes;
private List<SurfaceLineName> lineNames;
private List<SurfaceLineCode> lineCodes;
private List<ExternalLink> links;

public SurfaceAgency() {
Expand Down Expand Up @@ -65,19 +65,19 @@ public void setOperatindDays(DayFlags operatindDays) {
this.operatindDays = operatindDays;
}

public List<String> getLineNames() {
public List<SurfaceLineName> getLineNames() {
return lineNames;
}

public void setLineNames(List<String> lineNames) {
public void setLineNames(List<SurfaceLineName> lineNames) {
this.lineNames = lineNames;
}

public List<String> getLineCodes() {
public List<SurfaceLineCode> getLineCodes() {
return lineCodes;
}

public void setLineCodes(List<String> lineCodes) {
public void setLineCodes(List<SurfaceLineCode> lineCodes) {
this.lineCodes = lineCodes;
}

Expand All @@ -90,20 +90,21 @@ public void setLinks(List<ExternalLink> links) {
}



protected SurfaceAgency(Parcel in) {
agency = in.readInt();
frequency = in.readFloat();
duration = in.readFloat();
operatindDays = (DayFlags) in.readValue(DayFlags.class.getClassLoader());
if (in.readByte() == 0x01) {
lineNames = new ArrayList<String>();
in.readList(lineNames, String.class.getClassLoader());
lineNames = new ArrayList<SurfaceLineName>();
in.readList(lineNames, SurfaceLineName.class.getClassLoader());
} else {
lineNames = null;
}
if (in.readByte() == 0x01) {
lineCodes = new ArrayList<String>();
in.readList(lineCodes, String.class.getClassLoader());
lineCodes = new ArrayList<SurfaceLineCode>();
in.readList(lineCodes, SurfaceLineCode.class.getClassLoader());
} else {
lineCodes = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public class SurfaceLineCode implements Parcelable {
public SurfaceLineCode() {
}

public SurfaceLineCode(String code) {
this.code = code;
}

public String getCode() {
return code;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public class SurfaceLineName implements Parcelable {
public SurfaceLineName() {
}

public SurfaceLineName(String name) {
this.name = name;
}

public String getName() {
return name;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package nl.endevelopment.r2randroid.r2rlib.parser;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

import java.lang.reflect.Type;

import nl.endevelopment.r2randroid.r2rlib.models.SurfaceLineCode;

/**
* Created by jan on 28/08/2017.
*/

public class SurfaceLineCodeParser implements JsonDeserializer<SurfaceLineCode> {
@Override
public SurfaceLineCode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {

String code = json.getAsString();

return new SurfaceLineCode(code);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package nl.endevelopment.r2randroid.r2rlib.parser;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

import java.lang.reflect.Type;

import nl.endevelopment.r2randroid.r2rlib.models.SurfaceLineCode;
import nl.endevelopment.r2randroid.r2rlib.models.SurfaceLineName;

/**
* Created by jan on 28/08/2017.
*/

public class SurfaceLineNameParser implements JsonDeserializer<SurfaceLineName> {
@Override
public SurfaceLineName deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {

String name = json.getAsString();

return new SurfaceLineName(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
import nl.endevelopment.r2randroid.r2rlib.models.AirSegment;
import nl.endevelopment.r2randroid.r2rlib.models.DayFlags;
import nl.endevelopment.r2randroid.r2rlib.models.Segment;
import nl.endevelopment.r2randroid.r2rlib.models.SurfaceLineCode;
import nl.endevelopment.r2randroid.r2rlib.models.SurfaceLineName;
import nl.endevelopment.r2randroid.r2rlib.models.SurfaceSegment;
import nl.endevelopment.r2randroid.r2rlib.parser.BooleanParser;
import nl.endevelopment.r2randroid.r2rlib.parser.DayFlagsParser;
import nl.endevelopment.r2randroid.r2rlib.parser.RuntimeTypeAdapterFactory;
import nl.endevelopment.r2randroid.r2rlib.parser.SurfaceLineCodeParser;
import nl.endevelopment.r2randroid.r2rlib.parser.SurfaceLineNameParser;
import nl.endevelopment.r2randroid.r2rlib.utils.ConnectionUtils;
import okhttp3.Cache;
import okhttp3.HttpUrl;
Expand Down Expand Up @@ -93,9 +97,10 @@ public Response intercept(Chain chain) throws IOException {
/**
* get gson converter factory
* register type adapters here
*
* @return GsonConverterFactory
*/
public GsonConverterFactory getGsonConverterFactory(){
public GsonConverterFactory getGsonConverterFactory() {


//polymorphism for segment model
Expand All @@ -107,6 +112,8 @@ public GsonConverterFactory getGsonConverterFactory(){
Gson gson = new GsonBuilder()
.registerTypeAdapter(Boolean.class, new BooleanParser())
.registerTypeAdapter(DayFlags.class, new DayFlagsParser())
.registerTypeAdapter(SurfaceLineCode.class, new SurfaceLineCodeParser())
.registerTypeAdapter(SurfaceLineName.class, new SurfaceLineNameParser())
.registerTypeAdapterFactory(runtimeTypeAdapterFactory)
.create();

Expand Down

0 comments on commit 2bb9975

Please sign in to comment.