Skip to content

Instantly share code, notes, and snippets.

@smanek
smanek / gist:1421696
Created December 2, 2011 04:00
Test the Student Web Service
# List the existing students (there are none)
~$ curl http://127.0.0.1:8080/student/rest/students
[]
# Create some fake students, and check that they now present
~$ curl -d "name=Shaneal&dob=015-28-1986&courses=CS-301,CS-401,CS-501" http://127.0.0.1:8080/student/rest/students
1
~$ curl -d "name=John&dob=01-02-1984&courses=CS-101,ENG-201,MATH-304" http://127.0.0.1:8080/student/rest/students
2
~$ curl http://127.0.0.1:8080/student/rest/students
@Path("/students")
@Produces({MediaType.APPLICATION_JSON})
public class StudentResource {
private static final ObjectMapper MAPPER = new ObjectMapper();
// We'll just 'persist' data in memory for this test application
private static final Map<Integer, Student> STUDENTS = Maps.newConcurrentMap();
@GET
public class GuavaExamples {
private static final Log log = LogFactory.getLog(GuavaExamples.class);
public static void main(String[] args) {
// The MapMaker/CacheBuilder is my very favorite part of Guava
// In its most basic form, you can use it to specify default values for keys
final Map<String, List<Integer>> grades = new MapMaker()
.makeComputingMap(new Function<String, List<Integer>>() {
@JsonSerialize(using = CourseSerializer.class)
@JsonDeserialize(using = CourseDeserializer.class)
public static class Course {
private final Department department;
private final long courseNumber;
public Course(Department department, long courseNumber) {
assert department != null;
this.department = department;
["CS-101", "ENG-201", "MATH-51"]
[
{ "courseNumber" : 101,
"department" : "COMPUTER_SCIENCE",
"vanityName" : "Intro to Typing"
},
{ "courseNumber" : 201,
"department" : "ENGLISH",
"vanityName" : "Postmodern Deconstructionism"
},
{ "courseNumber" : 51,
public class ImmutableJson {
private static final ObjectMapper MAPPER = new ObjectMapper();
public static void main(String[] args) throws IOException {
// create a student
final Student student = new Student("John Doe", new Date(), true,
new Course("Intro to Typing", Department.COMPUTER_SCIENCE, 101),
new Course("Postmodern Deconstructionism", Department.ENGLISH, 201),
package com.arantaday.json;
import org.codehaus.jackson.map.ObjectMapper;
import java.io.IOException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
public class SimpleJson {
final int port = 2182;
final EmbeddedZookeeperServer server = EmbeddedZookeeperServer.builder().clientPort(port).build();
final RobustZooKeeper client = new RobustZooKeeper("localhost:" + port);
client.withLock("lockName",
new Runnable() {
@Override
public void run() {
System.out.println("I've got the lock while I'm running!");
}
@smanek
smanek / gist:1329932
Created November 1, 2011 04:24
Jersey JSON Backtrace
java.lang.AbstractMethodError
org.codehaus.jackson.map.AnnotationIntrospector$Pair.findSerializer(AnnotationIntrospector.java:1148)
org.codehaus.jackson.map.ser.BasicSerializerFactory.findSerializerFromAnnotation(BasicSerializerFactory.java:362)
org.codehaus.jackson.map.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:252)
org.codehaus.jackson.map.ser.StdSerializerProvider._createUntypedSerializer(StdSerializerProvider.java:782)
org.codehaus.jackson.map.ser.StdSerializerProvider._createAndCacheUntypedSerializer(StdSerializerProvider.java:735)
org.codehaus.jackson.map.ser.StdSerializerProvider.findValueSerializer(StdSerializerProvider.java:344)
org.codehaus.jackson.map.ser.StdSerializerProvider.findTypedValueSerializer(StdSerializerProvider.java:420)
org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:601)
org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:256)