/core/src/main/java/com/pc/dailymile/domain/converters/TypeConverter.java

http://dailymile-client.googlecode.com/ · Java · 40 lines · 19 code · 5 blank · 16 comment · 0 complexity · 40e3022ce50001607d07b662215da860 MD5 · raw file

  1. /*
  2. Copyright 2010 platers.code
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package com.pc.dailymile.domain.converters;
  14. import com.google.gson.JsonDeserializationContext;
  15. import com.google.gson.JsonDeserializer;
  16. import com.google.gson.JsonElement;
  17. import com.google.gson.JsonParseException;
  18. import com.google.gson.JsonPrimitive;
  19. import com.google.gson.JsonSerializationContext;
  20. import com.google.gson.JsonSerializer;
  21. import com.pc.dailymile.utils.Type;
  22. public class TypeConverter implements JsonDeserializer<Type>, JsonSerializer<Type> {
  23. public Type deserialize(JsonElement json, java.lang.reflect.Type typeOfT,
  24. JsonDeserializationContext context) throws JsonParseException {
  25. return Type.fromApiValue(json.getAsString());
  26. }
  27. public JsonElement serialize(Type type, java.lang.reflect.Type typeOfT,
  28. JsonSerializationContext context) {
  29. return new JsonPrimitive(type.getApiValue());
  30. }
  31. }