Zac Sweers
a1852a7315
Finish spotless license header configuration ( #1231 )
...
* Update spotless and enable copyright header bits again
* Reformat square copyright headers
* Create separate format configuration for external files
* Update CI to use java 15 final
* include stacktrace in ci failures
* Update ktlint to 0.39
* Disable java formatting on JDK 15
* Fix google header
2020-09-25 22:18:51 -04:00
Zac Sweers
538890e8c0
Switch to spotless and format code ( #1196 )
...
* Add spotless configuration
* Reformat!
* Add copyright config for build.gradle.kts files
* Add toeholds for headers
2020-08-27 23:40:15 -04:00
Jesse Wilson
2b5b3b5f8e
Simplify the internals of PolymorphicJsonAdapterFactory
...
We don't need a custom JsonAdapter subclass - we can just call through
unconditionally and fail if the type is unexpected.
2020-07-30 22:34:09 -04:00
Samuele Maci
cd31e5ce52
Extend PolymorphicJsonAdapterFactory to allow custom handling of unknown labels ( #1094 )
...
* PolymorphicJsonAdapter uses JsonAdapter as fallback value instead of defaultValue
* PolymorphicJsonAdapterFactory uses fallbackJsonAdapter instead of (defaultValue, defaultValueSet)
* Add testing coverage
2020-07-30 22:01:42 -04:00
sarthak sehgal
976a891568
small correction in given example
2020-05-18 12:11:24 +05:30
Jesse Wilson
ca207b2e06
Revert "Don't allow toJson() serialization on polymorphic defau… ( #1025 )
...
This reverts commit 6323a0b7c8
.
This makes it difficult for a client to take a server-provided value,
modify it, and send it back.
2019-11-16 22:04:57 -05:00
Zac Sweers
6323a0b7c8
Don't allow toJson() serialization on polymorphic default values
...
This type explicitly indicates an unknown value. This is an explosive case, but an alternative could be to just write null into the writer?
2019-10-31 15:13:22 -04:00
Jesse Wilson
02cf66f129
Specify precedence when a subtype has multiple labels
2019-10-26 22:57:00 -04:00
Zac Sweers
1978581b3d
Make Rfc3339DateJsonAdapter null-safe ( #910 )
...
* Move delegate to private final
* Make Rfc3339DateJsonAdapter null-safe
Resolves #723
2019-09-11 07:22:02 -04:00
Nuno Gomes
687acba760
removed limitation where subtypes should be unique ( #856 )
...
* removed limitation where subtypes should be unique
There can be use cases where different type labels should match with the same subtype
* added test for PolymorphicJsonAdapter non unique subtypes
2019-06-20 10:39:19 -05:00
Eric Cochran
be6f3eb2af
Unconditionally close the peeked JsonReader. ( #810 )
...
It doesn't have an effect now, but this is for the future when closing the peeked source also clears buffers.
2019-02-17 17:00:29 -08:00
Eric Cochran
126c8ea961
Support fail on unknown in PolymorphicJsonAdapterFactory. ( #792 )
...
Before, this would fail when skipping to find the index of the label.
Note that this still requires the type to have a label field.
2019-02-15 11:16:12 -08:00
Zac Sweers
fead71bca0
Add support for default values in PolymorphicJsonAdapterFactory
...
Picking from #741
Resolves #739
2018-12-31 16:21:57 -08:00
Eric Cochran
5f0b2ee8e3
Allow Object base type for PolymorphicJsonAdapterFactory. ( #744 )
...
* Allow Object base type for PolymorphicJsonAdapterFactory
This works now.
Using general types like Object, Map, or List for the base type is error-prone, but the checks for these cases are not worth the code cost.
* Delete redundant test.
Let's not encourage users to use Object as a base type by showing it in a test.
2018-11-18 10:15:41 -05:00
Jesse Wilson
89103b6d13
Rename RuntimeJsonAdapterFactory to PolymorphicJsonAdapterFactory
...
Also expand the documentation.
2018-10-20 00:47:48 -04:00
Jesse Wilson
1896e0f118
Merge pull request #697 from jocmp/master
...
Make RuntimeJsonAdapterFactory public
2018-10-19 23:33:06 -04:00
Jesse Wilson
6125d8c7b1
Don't decode into memory in RuntimeJsonAdapterFactory
...
Instead use our new flatten API to decode directly to the stream.
2018-10-19 12:07:58 -04:00
Jesse Wilson
f28bca609a
JSON flattening.
...
This is a new API that makes it possible to do more interesting things
with composition. It's currently write-only; doing composition on reads
is much more difficult.
2018-10-19 10:59:19 -04:00
Jesse Wilson
24ac43a799
Change RuntimeJsonAdapterFactory to peek for type names.
...
This is a bit awkward because JsonReader.Options doesn't tell you
what its values are.
Also awkward because we don't yet have an equivalent to stream
the encode of the value.
2018-10-09 23:10:31 -04:00
Jesse Wilson
fe22970973
Document how to register JsonAdapters
...
Closes: https://github.com/square/moshi/issues/698
2018-10-08 11:14:57 -04:00
Josiah Campbell
80f651a3eb
Make RuntimeJsonAdapterFactory public
2018-09-27 10:44:55 -05:00
Jesse Wilson
11241a2b02
Hide RuntimeJsonAdapterFactory for the forthcoming release.
...
We don't yet have the behavior we want for looking ahead at the type label.
2018-09-24 21:03:20 -04:00
Eric Cochran
810199a442
Disallow Object for RuntimeJsonAdapterFactory's base type.
2018-09-18 17:57:11 -07:00
Eric Cochran
67d07eb450
Add copyright header to EnumJsonAdapterTest.
2018-09-10 15:33:39 -07:00
Jesse Wilson
29bb93bc29
Include labels when encoding with RuntimeJsonAdapterFactory.
...
Otherwise the adapter is not symmetric.
2018-09-09 17:43:42 -04:00
Eric Cochran
8a8cde0ce3
Allow null fallback enum value in EnumJsonAdapter.
2018-08-31 00:51:34 -07:00
Eric Cochran
29bdc0aa45
Add EnumJsonAdapter to adapters module. ( #607 )
2018-08-07 15:05:56 -07:00
Eric Cochran
0f1fa3d385
Add RuntimeJsonAdapterFactory to adapters module. ( #606 )
...
* Add RuntimeJsonAdapterFactory to adapters module.
* Make RuntimeJsonAdapterFactory create null-safe adapters.
* Add copyright headers.
2018-08-06 04:35:53 -04:00
Eric Cochran
ee873b64f6
Remove unused import.
2018-07-26 17:28:15 -07:00
Jesse Wilson
5ad9d31bd8
Move modules into their own packages.
...
This sets the Automatic-Module-Name for moshi, moshi-adapters, and moshi-kotlin.
It moves moshi-adapters into its own .adapters package and forwards the existing
adapter. It moves the moshi-kotlin into its own .kotlin package and forwards the
existing adapter.
I'm not certain this is necessary or sufficient, but I think it's the right idea
for JPMS compatibility.
2018-02-07 04:41:06 -05:00
Eric Cochran
9deeb62e77
Add permalink to ISO8601Utils.java. ( #425 )
...
This file was removed from master a few months ago.
2018-01-10 21:57:00 -05:00
Eric Cochran
b7f771a70f
Add cause to malformed date string exception.
2017-06-20 00:15:11 -07:00
jwilson
1c6bebac1d
RFC3339 adapter.
...
Much thanks to Jackson for doing all the real work.
2015-09-26 18:51:50 -04:00