Java JSON Controller to Scala? -
Java JSON Controller to Scala? -
i having harder time admit understanding json documentation.
i convert json result scala, i'm pretty lost. have tried lot of things, i'm still learning scala well, none of worth posting i'm not sure if makes sense.
i using anorm orm in scala. id pk[long]
public static result checkname(string clubname){ objectnode jresult = json.newobject(); if (club.clubexists(clubname)) { jresult.put("error", "club name exists"); homecoming status(409, jresult); // 409 - conflict } else { jresult.put("status", "ok"); homecoming ok(jresult); } }
clubexists in model:
public static boolean clubexists(string name) { club club = find.where().eq("club_name", name).findunique(); homecoming (club != null); }
the rest of model pretty basic:
@id @generatedvalue(strategy = generationtype.sequence, generator = "club_seq") public long clubid; @column(unique=true, length = 50) public string clubname; public long creator; public datetime created; public club(string clubname, long creator) { this.clubname = clubname; this.creator = creator; this.created = new datetime(); } public static finder<long, club> find = new finder<long, club>(long.class, club.class); public static club create(string name, long creator) { club club = new club(name, creator); club.save(); homecoming club; }
public static result checkname(string clubname){ objectnode jresult = json.newobject(); if (club.clubexists(clubname)) { jresult.put("error", "club name exists"); homecoming status(409, jresult); // 409 - conflict } else { jresult.put("status", "ok"); homecoming ok(jresult); } }
in scala (adding as json
alter mime type):
def checkname(clubname:string) = action { val jresult = json.obj() if (club.exists(clubname)) { conflict(jresult) json } else { ok(jresult) json } }
java json scala playframework-2.0
Comments
Post a Comment