Commit Graph

390 Commits

Author SHA1 Message Date
jwilson
39dc305a14 JsonWriter.getPath(). 2015-06-09 23:00:40 -04:00
jwilson
dce373c37d Throw JsonDataException consistently.
We throw IllegalStateException when the application code is
internally inconsistent, such as when it closes and then writes
or similar.

We throw an IOException when the source JSON is structurally
invalid, such as when strings are unquoted in strict mode.

And we throw JsonDataException when the application code is
correct, and the JSON is well-formed, but the application code
and JSON disagree with one another.
2015-06-07 11:12:39 -04:00
jwilson
f829ac6ffb Use AssertJ instead of JUnit assertions. 2015-06-02 09:50:43 -04:00
jwilson
236e8bd62f Support @Nullable in Adapter Methods.
When the annotation is present, the adapter method is used. When
it isn't, it isn't.
2015-06-01 00:32:14 -04:00
jwilson
d6d9f9ead3 New @JsonQualifier annotation.
Works like JSR-330's @Qualifier annotation. You may have
multiple qualifiers, or none.
2015-05-31 13:07:21 -04:00
Jesse Wilson
629181ff8c Merge pull request #42 from square/jwilson_0525_adaptermethods
Adapter methods.
2015-05-25 14:46:50 -07:00
jwilson
71f0889842 Adapter methods.
This is a fun new API that could make writing JSON adapters
much easier.
2015-05-25 14:40:40 -07:00
jwilson
c8fd0e4bc2 Reject unrecognized enum constants with an exception.
Also promote enum adapter to StandardJsonAdapters.java.
2015-05-25 07:35:08 -07:00
Jesse Wilson
8003b6668b Merge pull request #32 from dandc87/ak_enum_support
EnumJsonAdapter
2015-05-25 07:25:09 -07:00
jwilson
912c07dafa Save an allocation by using Okio instead of substring. 2015-05-25 06:45:00 -07:00
Adam Koski
a0b177136d Squashed commit of the following:
commit f4e6b9aab54b270ca703794fde9370d00821dfca
Author: Adam Koski <dandc87@gmail.com>
Date:   Sun Apr 12 19:25:49 2015 -0700

    Add copyright headers and remove redundant test

commit 064dfbb5ec7c6ed8e60c91776ce0a4e90a29ff9e
Author: Adam Koski <dandc87@gmail.com>
Date:   Sun Apr 12 13:10:17 2015 -0700

    Fix error preventing merging

commit d80c00ef2b7220397dd074dd6ceb03b9be9ec416
Author: Adam Koski <dandc87@gmail.com>
Date:   Sun Apr 12 12:59:46 2015 -0700

    Switch to using name()

commit 7e68f21537a58843c0426c5e73028e12b0522b96
Author: Adam Koski <dandc87@gmail.com>
Date:   Sat Apr 11 22:37:25 2015 -0700

    Optimize enum value retrieval

commit 1422abd632ca147252f5b0698c8b19dc77ca3fac
Author: Adam Koski <dandc87@gmail.com>
Date:   Sat Apr 11 22:35:06 2015 -0700

    Add enum test for custom names

commit 8a7fefe28a98576f8db849fe83fb7973fefd1f12
Author: Adam Koski <dandc87@gmail.com>
Date:   Fri Apr 10 19:32:46 2015 -0700

    Add javadoc

commit 920b7c6883664df39d99eb206b933c4929157d84
Author: Adam Koski <dandc87@gmail.com>
Date:   Fri Apr 10 19:21:18 2015 -0700

    Rename class to match convention

commit 461e87aa02552e09d0c4a0feaf2971e6050aa994
Author: Adam Koski <dandc87@gmail.com>
Date:   Thu Apr 9 23:20:05 2015 -0700

    Add initial support for enums
2015-04-12 19:27:38 -07:00
Jesse Wilson
eece10d46e Merge pull request #35 from square/jw/expose-sink
Expose Sink as constructor type.
2015-04-12 15:36:32 -04:00
Jake Wharton
a085548014 Use BufferedSink for reading. Sink writing convenience method. 2015-04-12 14:41:04 -04:00
Jake Wharton
9fedfc8066 Switch types to be final. 2015-04-12 14:29:18 -04:00
Jesse Wilson
41b3b0acde Merge pull request #36 from square/jw/token
Make token a nested type of the reader.
2015-04-12 06:07:07 -04:00
Jake Wharton
47cd73df89 Make token a nested type of the reader.
This is the only class which uses these tokens and it does not deserve a top-level type.
2015-04-12 00:57:14 -04:00
Jake Wharton
5e757e6f39 Correct Javadoc code usage. 2015-04-12 00:25:07 -04:00
Jake Wharton
8af08de19e Clean up warnings for Java 7 language level. 2015-03-27 00:37:01 -04:00
jwilson
144f57ad4c JsonAdapterFactories can lookup types they create.
Without this, things fail with stack overflow exceptions.
2015-03-24 23:54:31 -04:00
jwilson
795f262106 Map adapter.
Limited to string keys for now.
2015-03-23 23:15:03 -04:00
jwilson
08becc119a Big start into ClassAdapter.
This borrows from Gson's UnsafeAllocator. I didn't actually
borrow much from Gson's reflective type adapter, but I'll need
to review that in follow up to see if I forgot anything that
Gson covers.

Most interesting design decision here is that fields are
serialized in alphabetical order. Also we're pretty nice
around detecting field collisiosn and failing early.
2015-03-23 00:13:04 -04:00
Jesse Wilson
5ff6b3dde9 Import Gson's LinkedHashTreeMap. 2015-01-04 11:01:39 -05:00
Jesse Wilson
b106c8610d Merge pull request #17 from square/jw/path-bugs
Fix bugs in getPath() with arrays of objects and arrays of arrays.
2014-12-22 16:10:02 -05:00
Jake Wharton
963e5939e9 Fix bugs in getPath() with arrays of objects and arrays of arrays.
Original commit: Gson r1303 by Jesse Wilson.
2014-12-22 12:34:27 -08:00
Jake Wharton
26f76806bc Enable JsonReader with Source. 2014-12-22 12:29:56 -08:00
Scott Blum
467e7cced8 Remove TypeLiteral, test fixes. 2014-08-19 17:03:44 -04:00
Scott Blum
9a713f80ed Add comments, fix nits 2014-08-14 01:38:44 -04:00
Scott Blum
1e4f375e75 Finish primitive adapters, add tests. 2014-08-13 19:40:09 -04:00
Scott Blum
806767169b Add the missing primitive converters. 2014-08-12 19:14:06 -04:00
Scott Blum
59af0357bb Fix a few missing 'fail()' on expected exceptions 2014-08-12 15:31:12 -04:00
Jesse Wilson
a067ecc55d Implement an array adapter. 2014-08-12 09:40:19 -04:00
Jesse Wilson
290e4f737a CollectionsJsonAdapter. 2014-08-11 21:16:35 -04:00
Jake Wharton
64155a46b2 Always buffer sink. 2014-08-11 10:51:51 -07:00
Jake Wharton
ba5479cf11 Convert JsonWriter to use Okio Sink. 2014-08-11 09:23:37 -07:00
Jesse Wilson
b6e26fd606 Import Gson's type resolver. 2014-08-11 09:28:10 -04:00
Jesse Wilson
93eddc9069 Initial JsonAdapter structure.
This is similar to the way Gson does its type adapters: factories that
can delegate and compose.

It's different because annotations are fundamental to the design.

It's also different because there are no APIs to convert to and from
JSON on the central object: instead callers must get the JSON adapter
they're interested in and do that there. This is potentially more
efficient because applications can hold the adapter they need.
2014-08-11 08:37:13 -04:00
Jesse Wilson
ac1b1027f8 Use indexOfElement in JsonReader.
This means we don't need to re-navigate through the segments
for every single character. Should be a small performance win.
2014-08-10 01:04:56 -04:00
Jesse Wilson
083d451e5c Make JsonReader and JsonWriter our own.
Drop proprietary Gson features (non-execute prefix, HTML safe chars).
Don't serialize nulls by default.
Add a String constructor to JsonReader.
Begin to migrate JsonReader to using Okio's buffer.
2014-08-10 00:13:05 -04:00
Jesse Wilson
2a43606b65 Import JsonReader and JsonWriter from Gson. 2014-08-09 12:20:43 -04:00
Jesse Wilson
ff08c841f1 Basic project structure. 2014-08-09 12:19:29 -04:00