After the
I get the following json from a HttpResponse
{" Result ":" Success " , "Team_registration": {"CURRENT_STATUS": "killed" "EXPIRATION_TIME": "2012-07-18T21: 29: 43Z", "id": 609, "team_id": 50,}} I retrieve the "results" as a string with Jackson and as a "team_registration" as a POJO (in Android) I present this amount:
HTPransaction Response = httpClient.execute (httpGet); If (response.getStatusLine (). GetStatusCode () == 200) {HttpEntity unit = response.getEntity (); String json = entityUtils.toString (unit); Maps & lt; String, Object & gt; Map = mapper.readValue (json, new type reference & lt; map & lt; string, object & gt; & gt; () {}); Result = (string) map.get ("result"); ResultRegistration = (Registration) map.get ("team_registration"); Registration class:
package be.radarwerk.app.model; Import Java.io.Serializable; Import java.util.Date; Import org.codehaus.jackson.annotate.JsonIgnore; Public Class Registration Signable [// Todo Is Applicable? Private static last long serial VERSIONUID = 1 L; Private Ent ID; Private string current status; Private date expiration time; @JasonInjor Private Volunteer Volunteer; @Jesun Ignore Private Team Team; Public registration () {} public registration (int id, string current status, voluntary volunteer, team team) {super; This.id = ID; This.currentStatus = currentStatus; this. Volunteer = Volunteer; This.team = Team; } Public int getId () {return ID; } Public string matching current status () {turn on current status; } Public volunteers receiving volunteers () {Return volunteers; } Public team getTeam () {Return team; } Public Date getExpirationTime () {return end time; }} The string works fine as "the result", but for "registration_moment" I exception: java.lang.ClassCastException: java.util.LinkedHashMap not registered in the registration
I have also tried to apply it in the string as a "result" and the method of mapping it the same way. Reed value on that wire There is no success.
Your class should be automatically deserialized if you modify it like this ( Note: Jackson 2.1+ Required !): @JsonIgnoreProperties ("team_id") @JsonNamingStrategy (PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy) Applies Public Class Registration Serializable {Private Static Final long serial VERSIONUID = 1 L; Private Ent ID; Private string current status; Private date expiration time; @JasonInjor Private Volunteer Volunteer; @Jesun Ignore Private Team Team; Public registration () {} // other code} Then, to deserialize your code:
registration registration; Last Jasonode Node = Mapper Roti (jsn); If (.. node.get ("result") textValue () equals ("success")) registration = mapper.readObject (node.get ("team_registration") cross (), Registration.class.);
No comments:
Post a Comment