Last active
August 29, 2015 14:12
-
-
Save leviyehonatan/1dcbb146fe34838ca534 to your computer and use it in GitHub Desktop.
gson serialization yields null
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.util.List; | |
public class LoginInfo { | |
public class DeviceInfo { | |
public String deviceId; | |
public String deviceType; | |
public String deviceOs; | |
public int deviceVersion; | |
public boolean deviceScanAlways; | |
} | |
public class SdkIdentity { | |
public String sdkKey; | |
public String userId; | |
} | |
public class Data { | |
public DeviceInfo deviceInfo; | |
public List<SdkIdentity> sdk_identities; | |
} | |
public Data data; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.util.ArrayList; | |
import com.google.gson.Gson; | |
public class Test { | |
public static void main(String[] args) { | |
LoginInfo loginInfo = new LoginInfo() { | |
{ | |
data = new Data() { | |
{ | |
deviceInfo = new DeviceInfo() { | |
{ | |
deviceId = "dfs"; | |
deviceOs = ""; | |
deviceScanAlways = false; | |
deviceVersion = 5; | |
deviceType = "type"; | |
} | |
}; | |
sdk_identities = new ArrayList<SdkIdentity>() { | |
{ | |
add(new SdkIdentity() { | |
{ | |
sdkKey = "xxx"; | |
userId = "none"; | |
} | |
}); | |
} | |
}; | |
} | |
}; | |
} | |
}; | |
Gson gson = new Gson(); | |
System.out.println(gson.toJson(loginInfo)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
public static void main(String[] args) {