Skip to content

Commit

Permalink
Replace Nat Pryce's Maybe type with Optional from Google Guava
Browse files Browse the repository at this point in the history
Bump dep's:
- junit -> 4.10
- Woodstox -> 4.1.2
- Jackson -> 1.9.1
  • Loading branch information
chids committed Oct 28, 2011
1 parent 426871e commit 21f4252
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 246 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Everything throws IOException which either means you screwed up your serializati
#### Dependencies
* SLF4J: We depend on [SLF4J](http://www.slf4j.org/) so that you can plug in whatever logging you see fit
* [Jackson](http://jackson.codehaus.org/) and [Woodstox](http://woodstox.codehaus.org/) for the actual serialization
* [Maybe](https://github.com/npryce/maybe-java) we use [Nat Pryce's](http://www.natpryce.com/) Maybe type quite extensively and thus this library provides API methods that accepts maybes. Currently there's no Maven distribution of this library so we simply bundled the jar, for now
* [Guava](http://guava-libraries.googlecode.com) we support serializing Optional instances.

### Background and rationale

Expand All @@ -100,4 +100,4 @@ We have a lot of HTTP based API services. These are almost entirely accessed usi
There are lots of good and great Java libraries out there for serializing POJOs to XML or JSON. We're using, have used or have tried [Jaxb](http://jaxb.java.net/), [Jackson](http://jackson.codehaus.org/), [Woodstox](http://woodstox.codehaus.org/), [Simple](http://simple.sourceforge.net/), [XStream](http://xstream.codehaus.org/), [org.json](http://www.json.org/java/index.html), [VTD-XML](http://vtd-xml.sourceforge.net/) and [Gson](http://code.google.com/p/google-gson/).

#### The problem
We're not interested in de-serialization. Period. A few of our services accept small JSON inputs - we handle that input "manually", often with [Gson](http://code.google.com/p/google-gson/). Not requiring deserialization makes the quirks in [insert-library-name-here] a much bigger _pain_. For example we don't want to add private no-arg constructors to our immutable POJOs. Then when you've started to irritate yourself on that you can also choose to irritate yourself on the annotations, or the lack of annotations, or the inability to serialize [insert-collection-class-here] without having to write an adapter - whichever fuels your rage. And when you've become agitated enough you may write a library such as this, for fun and dubious profit.
We're not interested in de-serialization. Period. A few of our services accept small JSON inputs - we handle that input "manually", often with [Gson](http://code.google.com/p/google-gson/). Not requiring deserialization makes the quirks in [insert-library-name-here] a much bigger _pain_. For example we don't want to add private no-arg constructors to our immutable POJOs. Then when you've started to irritate yourself on that you can also choose to irritate yourself on the annotations, or the lack of annotations, or the inability to serialize [insert-collection-class-here] without having to write an adapter - whichever fuels your rage. And when you've become agitated enough you may write a library such as this, for fun and dubious profit.
14 changes: 7 additions & 7 deletions lib/src/main/java/se/hitta/simplerialize/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.io.Writer;
import java.util.Iterator;

import com.natpryce.maybe.Maybe;
import com.google.common.base.Optional;

/**
* The interface for all concrete {@link Serializer} implementations.
Expand Down Expand Up @@ -131,17 +131,17 @@ public interface Serializer extends Flushable, Closeable
Serializer endContainer() throws IOException;

/**
* If the supplied {@link Maybe} is known write it using an adapter
* If the supplied {@link Optional} is known write it using an adapter
* otherwise do nothing.
*
* @param target The {@link Maybe} whose elements to serialize
* @param target The {@link Optional} whose elements to serialize
* @return this {@link Serializer} instance to allow call chaining
* @throws IOException if there's either a format problem (ie your usage of
* the library produced illegal XML or JSON) or if an {@link IOException}
* occurs when writing to the underlying {@link OutputStream} or
* {@link Writer}.
*/
Serializer writeWithAdapter(Maybe<?> target) throws IOException;
Serializer writeWithAdapter(Optional<?> target) throws IOException;

/**
* Write the supplied target object using the adapter found by this
Expand Down Expand Up @@ -220,8 +220,8 @@ public interface Serializer extends Flushable, Closeable
<T extends Number>Serializer writeNameValue(final String name, final T value) throws IOException;

/**
* If the supplied {@link Maybe} is known, write a {@link String} name and
* the value of the {@link Maybe}. Otherwise, do nothing.
* If the supplied {@link Optional} is known, write a {@link String} name and
* the value of the {@link Optional}. Otherwise, do nothing.
*
* @param name
* @param value
Expand All @@ -231,7 +231,7 @@ public interface Serializer extends Flushable, Closeable
* occurs when writing to the underlying {@link OutputStream} or
* {@link Writer}.
*/
Serializer writeNameValue(String name, Maybe<?> value) throws IOException;
Serializer writeNameValue(String name, Optional<?> value) throws IOException;

/**
* Print the output of this {@link Serializer} to the supplied
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import se.hitta.simplerialize.AdapterMapper;
import se.hitta.simplerialize.Serializer;

import com.natpryce.maybe.Maybe;
import com.google.common.base.Optional;

abstract class AbstractSerializer implements Serializer
{
Expand All @@ -36,14 +36,14 @@ abstract class AbstractSerializer implements Serializer

/*
* (non-Javadoc)
* @see se.hitta.simplerialize.Serializer#writeWithAdapter(com.natpryce.maybe.Maybe)
* @see se.hitta.simplerialize.Serializer#writeWithAdapter(com.google.common.base.Optional)
*/
@Override
public final Serializer writeWithAdapter(final Maybe<?> target) throws IOException
public final Serializer writeWithAdapter(final Optional<?> target) throws IOException
{
if(target != null && target.isKnown())
if(target != null && target.isPresent())
{
writeWithAdapter(target.value());
writeWithAdapter(target.get());
}
return this;
}
Expand Down
Loading

0 comments on commit 21f4252

Please sign in to comment.