Back to project page Android-CleanArchitecture.
The source code is released under:
Apache License
If you think the Android project Android-CleanArchitecture listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * Copyright (C) 2014 android10.org. All rights reserved. * @author Fernando Cejas (the android10 coder) *//*w w w. j a v a 2 s . c om*/ package com.fernandocejas.android10.sample.data.cache.serializer; import com.fernandocejas.android10.sample.data.entity.UserEntity; import com.google.gson.Gson; /** * Class user as Serializer/Deserializer for user entities. */ public class JsonSerializer { private final Gson gson = new Gson(); public JsonSerializer() { //empty } /** * Serialize an object to Json. * * @param userEntity {@link UserEntity} to serialize. */ public String serialize(UserEntity userEntity) { String jsonString = gson.toJson(userEntity, UserEntity.class); return jsonString; } /** * Deserialize a json representation of an object. * * @param jsonString A json string to deserialize. * @return {@link UserEntity} */ public UserEntity deserialize(String jsonString) { UserEntity userEntity = gson.fromJson(jsonString, UserEntity.class); return userEntity; } }