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
# 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 |
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
@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 |
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
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>>() { |
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
@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; |
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
["CS-101", "ENG-201", "MATH-51"] |
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
[ | |
{ "courseNumber" : 101, | |
"department" : "COMPUTER_SCIENCE", | |
"vanityName" : "Intro to Typing" | |
}, | |
{ "courseNumber" : 201, | |
"department" : "ENGLISH", | |
"vanityName" : "Postmodern Deconstructionism" | |
}, | |
{ "courseNumber" : 51, |
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
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), |
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 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 { |
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
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!"); | |
} |
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
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) |
NewerOlder