23/09/2013
Scala + Resteasy + Jetty 9 + Jackson
I have been start playing with scala and rest. Being a scala newbie I struggled a bit, but that's the best way to learn right ?
Here a simple sbt project that expose a json rest api in Scala https://github.com/undeploy/scala-resteasy-jetty
22/09/2013
Playing around with ios
Here a little project I worked this weekend that shows how to take a picture and the gps position on ios, hope can be helpful to some other
that like me i starting playing around with Object-C and ios : https://github.com/undeploy/iMovi
05/02/2013
AngularJS template and single quote
Are you using AngularJS template ? Well the single quote in the ng-include are important! If you don't type that the template will not work ;)
<div ng-include="'/header.html'"></div>
04/02/2013
Spring + Resteasy + WRITE_DATES_AS_TIMESTAMPS
If you want to configure the ObjectMapper to serialize date as string well here it is.
First you create your custom implementation of ContextResolver<ObjectMapper> :
@Provider public class MyJacksonConfig implements ContextResolver<ObjectMapper> { @Override public ObjectMapper getContext(Class type) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(Feature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.setAnnotationIntrospector( new Pair( new JacksonAnnotationIntrospector(), new JaxbAnnotationIntrospector())); return mapper; } }
then you just need to add the provider to the resteasy.providers list in the web.xml :
<context-param>
<param-name>resteasy.providers</param-name>
<param-value>org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider,org.rest.MyJacksonConfig</param-value>
</context-param>
and voila', your DateTime will be serialized as ISO string format (eg: Created:2013-02 04T21:07:00.688+01:00)
Hope this will save some of your time guys :)
27/01/2013
JAXB inheritance and XmlElementRef
If you want JAXB to use the subclass element root name (e.g in this case NotEmpty, NotNull), you have to indicate so adding the @XmlElementRef annotation on the collection containing the list of objects hierarchy.
@XmlRootElement(name = "Property")
@XmlAccessorType(XmlAccessType.FIELD)
public class Property {
public enum Type {
UUID,
STRING,
INTEGER,
LONG,
DECIMAL,
FLOAT,
DOUBLE,
BOOLEAN,
DATETIME
}
@NotNull
@XmlElement(name = "Name")
private String name;
@NotNull
@XmlElement(name = "Type")
private Type type;
@XmlElementWrapper(name = "Constraints")
@XmlElementRef
private List<PropertyConstraint> constraints;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public void setConstraints(List<PropertyConstraint> constraints) {
this.constraints = constraints;
}
public List<PropertyConstraint> getConstraints() {
return constraints;
}
}
@XmlRootElement(name = "NotEmpty")
@XmlAccessorType(XmlAccessType.FIELD)
public class NotEmptyContraint extends PropertyConstraint {
}
@XmlRootElement(name = "NotNull")
@XmlAccessorType(XmlAccessType.FIELD)
public class NotNullConstraint extends PropertyConstraint {
}
public abstract class PropertyConstraint {
}
public static void main(String[] args) throws JAXBException {
Property p = new Property();
p.setType(Type.BOOLEAN);
p.setName("Name");
List<PropertyConstraint> asList = Arrays.asList(new PropertyConstraint[] {new NotEmptyContraint(), new NotNullConstraint()});
p.setConstraints(asList);
JAXBContext jaxc = JAXBContext.newInstance(Property.class, NotNullConstraint.class, NotEmptyContraint.class);
Marshaller m = jaxc.createMarshaller();
m.marshal(p, System.out);
}
will print :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Property>
<Name>Name</Name>
<Type>BOOLEAN</Type>
<Constraints>
<NotEmpty></NotEmpty>
<NotNull></NotNull>
</Constraints>
</Property>
Subscribe to:
Posts (Atom)