Skip to content

Instantly share code, notes, and snippets.

@AVGP
Created September 21, 2012 15:13
Show Gist options
  • Save AVGP/3762089 to your computer and use it in GitHub Desktop.
Save AVGP/3762089 to your computer and use it in GitHub Desktop.
Sample Java Library
package org.avgp.sample;
import org.avgp.sample.User;
import org.json.JSONString;
public class Message implements JSONString {
protected User sender;
protected User receipient;
protected String content;
public Message(User from, User to, String content) {
this.sender = from;
this.receipient = to;
this.content = content;
}
public String toJSONString() {
return "{sender: " + this.sender.toJSONString() + ", receipient: " + this.receipient.toJSONString() + ", content: \"" + this.content + "\"}";
}
}
package org.avgp.sample;
import java.util.UUID;
import org.json.JSONString;
public class User implements JSONString {
private String name;
private UUID id;
public User(String name) {
this.name = name;
this.id = UUID.randomUUID();
}
public String getName() {
return this.name;
}
public UUID getId() {
return this.id;
}
public String toJSONString() {
return "{name: \"" + this.name + "\", id: \"" + this.id.toString() + "\"}";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment