├── .gitignore
├── BUILD.md
├── CHANGES.md
├── LICENSE
├── README.md
├── SECURITY.md
├── VERSION_PREFIX
├── bin
├── classpath
└── roundtrip
├── build.clj
├── build
├── doc
├── package
├── release
└── revision
├── deps.edn
├── pom.xml
└── src
├── main
└── java
│ └── com
│ └── cognitect
│ └── transit
│ ├── ArrayReadHandler.java
│ ├── ArrayReader.java
│ ├── DefaultReadHandler.java
│ ├── Keyword.java
│ ├── Link.java
│ ├── MapReadHandler.java
│ ├── MapReader.java
│ ├── Named.java
│ ├── Ratio.java
│ ├── ReadHandler.java
│ ├── Reader.java
│ ├── SPI
│ └── ReaderSPI.java
│ ├── Symbol.java
│ ├── TaggedValue.java
│ ├── TransitFactory.java
│ ├── URI.java
│ ├── WriteHandler.java
│ ├── Writer.java
│ └── impl
│ ├── AbstractEmitter.java
│ ├── AbstractParser.java
│ ├── AbstractWriteHandler.java
│ ├── Cache.java
│ ├── Constants.java
│ ├── Emitter.java
│ ├── JsonEmitter.java
│ ├── JsonParser.java
│ ├── JsonVerboseEmitter.java
│ ├── KeywordImpl.java
│ ├── LinkImpl.java
│ ├── ListBuilderImpl.java
│ ├── MapBuilderImpl.java
│ ├── MsgpackEmitter.java
│ ├── MsgpackParser.java
│ ├── Parser.java
│ ├── Quote.java
│ ├── RatioImpl.java
│ ├── ReadCache.java
│ ├── ReadHandlerMap.java
│ ├── ReadHandlers.java
│ ├── ReaderFactory.java
│ ├── SymbolImpl.java
│ ├── Tag.java
│ ├── TagFinder.java
│ ├── TagProvider.java
│ ├── TagProviderAware.java
│ ├── TaggedValueImpl.java
│ ├── URIImpl.java
│ ├── Util.java
│ ├── WriteCache.java
│ ├── WriteHandlerMap.java
│ ├── WriteHandlers.java
│ └── WriterFactory.java
└── test
└── java
└── com
└── cognitect
└── transit
├── TestRoundtrip.java
├── TransitJSONMachineModeTest.java
├── TransitMPTest.java
└── TransitTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Package Files #
4 | *.jar
5 | *.war
6 | *.ear
7 |
8 | *.iml
9 | .idea/
10 | target/
11 | design.org
12 |
13 | *~
14 |
15 | .cpcache
16 | .java-version
17 |
--------------------------------------------------------------------------------
/BUILD.md:
--------------------------------------------------------------------------------
1 | ## Build (internal)
2 |
3 | ### Version
4 |
5 | The build version is automatically incremented. To determine the
6 | current build version:
7 |
8 | build/version
9 |
10 | ### Package
11 |
12 | Packaging builds the maven artifacts in `target/package` and installs
13 | it into the local maven repository. To package:
14 |
15 | build/package
16 |
17 | ### Deploy
18 |
19 | Deployment requires that the AWS CLI tools be installed (see
20 | https://aws.amazon.com/cli/).
21 |
22 | The deploy script runs the package script, and then deploys the
23 | artifacts to the S3 bucket "mrel". To deploy:
24 |
25 | build/release
26 |
27 | ### Docs
28 |
29 | To build and deploy api documentation:
30 |
31 | build/doc
32 |
--------------------------------------------------------------------------------
/CHANGES.md:
--------------------------------------------------------------------------------
1 | # transit-java 1.0
2 |
3 | ### 1.0.371 / 2023-03-31
4 |
5 | * Update jackson-core to 2.14.2
6 | * Update jaxb-api to 2.4.0-b180830.0359
7 |
8 | ### 1.0.366 / 2023-03-31
9 |
10 | * Fix for https://github.com/cognitect/transit-clj/issues/37 - error reading cmap with null key
11 |
12 | ### 1.0.362 / 2022-02-04
13 |
14 | * Fix for https://github.com/cognitect/transit-clj/issues/47 - interpose a transformer on tag resolution when present. This handles the case where a transformer may convert an object into a form that the marhsaling phase may not be able to handle. This bifurcation between the classifying tag and the marshaled form was specifically causing issues in transit-clj where symbol map keys with metadata did not marshal into a stringable form but were classified as stringable earlier in the write phase.
15 | * Remove dependency on org.apache.commons.codec, use java.util.Base64
16 | * Other minor dep version updates
17 |
18 | ### 1.0.343 / 2020-02-18
19 |
20 | * No changes, just version
21 |
22 | ### 0.8.337 / 2018-08-17
23 |
24 | * Add explicit jaxb-api dependency for Java 9+ (issue #28)
25 |
26 | ### 0.8.332 / 2018-03-30
27 |
28 | * Add support for transform function in writer
29 | * Compile to Java 1.8 target (previously 1.6)
30 |
31 | ### 0.8.327 / 2017-03-31
32 |
33 | * Add support for defaultWriteHandler in TransitFactory.writer()
34 |
35 | ### 0.8.324 / 2017-03-13
36 |
37 | * Update jackson-core dependency from 2.3.2 to 2.8.7
38 |
39 | ### 0.8.319 / 2016-11-18
40 |
41 | * Fix double check locking of non-thread-safe handler caches
42 |
43 | ### 0.8.316 / 2016-09-30
44 |
45 | * WriteHandler thread safety improvements
46 |
47 | ### 0.8.313 / 2016-07-27
48 |
49 | * Updated msgpack dependency to 0.6.12
50 |
51 | ### 0.8.311 / 2015-10-22
52 |
53 | * Simplified commons-codec dependency to be more direct
54 | * Simplified jackson-core dependency to reduce transitive dependencies (#11)
55 |
56 | ### 0.8.307 / 2015-10-09
57 |
58 | * Fixed #15: Wrap SimpleDateFormat in ThreadLocal
59 |
60 | ### 0.8.304 / 2015-08-07
61 |
62 | * ReadHandlerMap and WriteHandlerMap
63 |
64 | ### 0.8.285 / 2015-03-13
65 |
66 | * cache read and write handlers
67 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # transit-java
2 |
3 | Transit is a data format and a set of libraries for conveying values between applications written in different languages. This library provides support for marshalling Transit data to/from Java.
4 |
5 | * [Rationale](https://blog.cognitect.com/blog/2014/7/22/transit)
6 | * [API docs](https://cognitect.github.io/transit-java/)
7 | * [Specification](https://github.com/cognitect/transit-format)
8 |
9 | This implementation's major.minor version number corresponds to the version of the Transit specification it supports.
10 |
11 | _NOTE: Transit is intended primarily as a wire protocol for transferring data between applications. If storing Transit data durably, readers and writers are expected to use the same version of Transit and you are responsible for migrating/transforming/re-storing that data when and if the transit format changes._
12 |
13 | ## Releases and Dependency Information
14 |
15 | * Latest release: 1.0.371
16 | * [All Released Versions](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.cognitect%22%20AND%20a%3A%22transit-java%22)
17 |
18 | [Maven](https://maven.apache.org/) dependency information:
19 |
20 | ```xml
21 |
22 | com.cognitect
23 | transit-java
24 | 1.0.371
25 |
26 | ```
27 |
28 | ## Usage
29 |
30 | ```java
31 | import java.io.ByteArrayOutputStream;
32 | import java.io.ByteArrayInputStream;
33 | import com.cognitect.transit.TransitFactory;
34 | import com.cognitect.transit.Reader;
35 | import com.cognitect.transit.Writer;
36 |
37 | // Write the data to a stream
38 | OutputStream out = new ByteArrayOutputStream();
39 | Writer writer = TransitFactory.writer(TransitFactory.Format.MSGPACK, out);
40 | writer.write(data);
41 |
42 | // Read the data from a stream
43 | InputStream in = new ByteArrayInputStream(out.toByteArray());
44 | Reader reader = TransitFactory.reader(TransitFactory.Format.MSGPACK, in);
45 | Object data = reader.read();
46 | ```
47 |
48 | ### Custom write handler
49 |
50 | ```java
51 | public class Point {
52 | public final int x;
53 | public final int y;
54 | public Point(int x,int y) {this.x = x; this.y = y;}
55 | public String toString() { return "Point at " + x + ", " + y; }
56 | public boolean equals(Object other) { return other instanceof Point &&
57 | ((Point)other).x == x &&
58 | ((Point)other).y == y; }
59 | public int hashCode() { return x * y; }
60 | }
61 |
62 | Map> customHandlers = new HashMap>(){{
63 | put(Point.class, new WriteHandler() {
64 | @Override
65 | public String tag(Object o) { return "point"; }
66 | @Override
67 | public Object rep(Object o) { return Arrays.asList(((Point)o).x, ((Point)o).y); }
68 | @Override
69 | public String stringRep(Object o) { return rep(o).toString(); }
70 | @Override
71 | public WriteHandler getVerboseHandler() { return this; }
72 | });
73 | }};
74 | OutputStream out = new ByteArrayOutputStream();
75 | Writer w = TransitFactory.writer(TransitFactory.Format.JSON, out, TransitFactory.writeHandlerMap(customHandlers));
76 | w.write(new Point(37, 42));
77 | System.out.print(out.toString());
78 | ;; => ["~#point",[37,42]]
79 | ```
80 |
81 | ### Custom read handler
82 |
83 | ```java
84 | Map> customHandlers = new HashMap>() {{
85 | put("point", new ReadHandler() {
86 | @Override
87 | public Object fromRep(Object o) {
88 | List coords = (List) o;
89 | int x = ((Long) coords.get(0)).intValue();
90 | int y = ((Long) coords.get(1)).intValue();
91 | return new Point(x,y);
92 | }
93 | });
94 | }};
95 | InputStream in = new ByteArrayInputStream("[\"~#point\",[37,42]]".getBytes());
96 | Reader reader = TransitFactory.reader(TransitFactory.Format.JSON, in, customHandlers);
97 | System.out.print(reader.read());
98 | // => Point at 37, 42
99 | ```
100 |
101 | ### Custom default write handler
102 |
103 | ```java
104 | WriteHandler customDefaultWriteHandler = new WriteHandler() {
105 | @Override
106 | public String tag(Object o) { return "unknown"; }
107 | @Override
108 | public Object rep(Object o) { return o.toString(); }
109 | @Override
110 | public String stringRep(Object o) { return o.toString(); }
111 | @Override
112 | public WriteHandler getVerboseHandler() { return this; }
113 | };
114 | OutputStream out = new ByteArrayOutputStream();
115 | Writer w = TransitFactory.writer(TransitFactory.Format.JSON, out, customDefaultWriteHandler);
116 | w.write(new Point(37,42));
117 | System.out.print(out.toString());
118 | // => "[\"~#unknown\",\"Point at 37, 42\"]"
119 | ```
120 |
121 | ### Custom default read handler
122 |
123 | ```java
124 | DefaultReadHandler readHandler = new DefaultReadHandler() {
125 | @Override
126 | public Object fromRep(String tag, Object rep) {
127 | return tag + ": " + rep.toString();
128 | }
129 | };
130 | InputStream in = new ByteArrayInputStream("[\"~#unknown\",[37,42]]".getBytes());
131 | Reader reader = TransitFactory.reader(TransitFactory.Format.JSON, in, readHandler);
132 | System.out.print(reader.read());
133 | // => unknown: [37, 42]
134 | ```
135 |
136 | ## Default Type Mapping
137 |
138 | |Transit type|Write accepts|Read returns|
139 | |------------|-------------|------------|
140 | |null|null|null|
141 | |string|java.lang.String|java.lang.String|
142 | |boolean|java.lang.Boolean|java.lang.Boolean|
143 | |integer|java.lang.Byte, java.lang.Short, java.lang.Integer, java.lang.Long|java.lang.Long|
144 | |decimal|java.lang.Float, java.lang.Double|java.lang.Double|
145 | |keyword|cognitect.transit.Keyword|cognitect.transit.Keyword|
146 | |symbol|cognitect.transit.Symbol|cognitect.transit.Symbol|
147 | |big decimal|java.math.BigDecimal|java.math.BigDecimal|
148 | |big integer|java.math.BigInteger|java.math.BigInteger|
149 | |time|java.util.Date|long|
150 | |uri|java.net.URI, cognitect.transit.URI|cognitect.transit.URI|
151 | |uuid|java.util.UUID|java.util.UUID|
152 | |char|java.lang.Character|java.lang.Character|
153 | |array|Object[],primitive arrays|java.util.ArrayList|
154 | |list|java.util.List|java.util.LinkedList|
155 | |set|java.util.Set|java.util.HashSet|
156 | |map|java.util.Map|java.util.HashMap|
157 | |link|cognitect.transit.Link|cognitect.transit.Link|
158 | |ratio +|cognitect.transit.Ratio|cognitect.transit.Ratio|
159 |
160 | \+ Extension type
161 |
162 | ## Layered Implementations
163 |
164 | This library is specifically designed to support layering Transit
165 | implementations for other JVM-based languages on top of it. There are
166 | three steps to implementing a library for a new language on top of
167 | this:
168 |
169 | - Implement WriteHandlers and ReadHandlers specific for the target
170 | language. Typically, WriteHandlers will be used _in addition to_ the
171 | ones provided by the Java library (see
172 | TransitFactory.defaultWriteHandlers). ReadHandlers will be used _in
173 | place of_ some of the ones provided by the Java Libary (see
174 | TransitFactory.defaultReadHandlers).
175 |
176 | - Implement a factory API to create Readers and Writers. In general,
177 | Readers and Writers encapsulate the stream they work with. The APIs
178 | should enable an application to provide custom WriteHandlers and
179 | ReadHandlers, which get merged with the ones defined by the new
180 | library as well as the defaults provided by the Java library. The
181 | Reader API should also provide a way to specify a default behavior
182 | if no ReadHandler is available for a specific Transit value (see
183 | com.cognitect.transit.DefaultReadHandler). The factory API should
184 | delegate to TransitFactory to create Readers and Writers with the
185 | correct options.
186 |
187 | - Implement a MapReader and an ArrayReader for unmarshaling these
188 | Transit ground types into objects appropriate for the target
189 | language. In the factory API for creating Readers, use each new Reader's
190 | com.cognitect.transit.SPI.ReaderSPI interface to attach instances
191 | of the new library's custom MapReader and ArrayReader
192 | implementations to a Reader before returning it. This must be done
193 | before the Reader instance is used to read data.
194 |
195 | N.B. The ReaderSPI interface is in an impl package because it is only
196 | intended to be used by layered Transit libraries, not by
197 | applications using Transit.
198 |
199 | The [Clojure Transit library](https://github.com/cognitect/transit-clj)
200 | is implemented using this layering approach and can be used as an
201 | example of how to implement support for additional JVM languages
202 | without having to implement all of Transit from scratch.
203 |
204 | ## Contributing
205 |
206 | This library is open source, developed internally by Cognitect. We welcome discussions of potential problems and enhancement suggestions on the [transit-format mailing list](https://groups.google.com/forum/#!forum/transit-format). Issues can be filed using GitHub [issues](https://github.com/cognitect/transit-java/issues) for this project. Because transit is incorporated into products and client projects, we prefer to do development internally and are not accepting pull requests or patches.
207 |
208 | ## Copyright and License
209 |
210 | Copyright © 2014 Cognitect
211 |
212 | Licensed under the Apache License, Version 2.0 (the "License");
213 | you may not use this file except in compliance with the License.
214 | You may obtain a copy of the License at
215 |
216 | https://www.apache.org/licenses/LICENSE-2.0
217 |
218 | Unless required by applicable law or agreed to in writing, software
219 | distributed under the License is distributed on an "AS IS" BASIS,
220 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
221 | See the License for the specific language governing permissions and
222 | limitations under the License.
223 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy for Nubank Open Source Projects
2 |
3 | ## Supported Versions
4 |
5 | Nubank supports the latest version of each of our open-source projects. Once a new version is released, we stop providing patches for security issues in older versions.
6 |
7 | ## Reporting Security Issues
8 |
9 | Your efforts to responsibly disclose your findings are sincerely appreciated and will be taken into account to acknowledge your contributions.
10 | If you discover a vulnerability, please do the following:
11 |
12 | 1. E-mail your findings to [security@nubank.com.br](mailto:security@nubank.com.br). If the issue is sensitive, please use [our PGP key](https://nubank.com.br/.well-known/security.txt) to encrypt your communications with us.
13 | 2. Do not take advantage of the vulnerability or problem you have discovered.
14 | 3. Do not reveal the problem to others until it has been resolved.
15 | 4. Provide sufficient information to reproduce the problem so we can resolve it as quickly as possible.
16 | 5. You will receive a response from us acknowledging receipt of your vulnerability report.
17 | 6. You'll receive regular updates about our progress.
18 | 7. Once the issue is resolved, we would like to mention your name in any dispatches about the issue so that we can credit you for your discovery. Please engage in responsible privacy practices when disclosing bugs to us, and we'll handle each report with utmost urgency.
19 |
20 | ## Preferred Languages
21 |
22 | We prefer all communications to be in English.
23 |
24 | ## Policy Adherence
25 |
26 | We greatly value your assistance in discovering and reporting vulnerabilities, and look forward to working with users who wish to help ensure Nubank's open-source projects' safety and security. Thank you for supporting Nubank's mission and helping ensure the highest levels of security for our community!
27 |
--------------------------------------------------------------------------------
/VERSION_PREFIX:
--------------------------------------------------------------------------------
1 | 1.0
2 |
--------------------------------------------------------------------------------
/bin/classpath:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | set -e
4 |
5 | cd `dirname $0`/..
6 |
7 | mvn dependency:build-classpath | awk '/\[INFO\] Dependencies classpath:/{flag=1;next}/\[INFO\] --/{flag=0}flag{print}'
8 |
--------------------------------------------------------------------------------
/bin/roundtrip:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | cd `dirname $0`/..
4 |
5 | exec java -Xmx1g -server -cp `bin/classpath`:target/classes:target/test-classes com.cognitect.transit.TestRoundtrip "$@"
6 |
--------------------------------------------------------------------------------
/build.clj:
--------------------------------------------------------------------------------
1 | (ns build
2 | (:refer-clojure :exclude [compile])
3 | (:require [clojure.tools.build.api :as b]))
4 |
5 | (def basis (b/create-basis nil))
6 | (def lib 'com.cognitect/transit-java)
7 | (def version (str (slurp "VERSION_PREFIX") "." (b/git-count-revs nil)))
8 | (def class-dir "target/classes")
9 |
10 | (defn compile
11 | [_]
12 | (b/delete {:path "target"})
13 | (b/javac {:src-dirs ["src/main/java"] :class-dir class-dir :basis basis}))
14 |
--------------------------------------------------------------------------------
/build/doc:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 |
5 | echo -e "Building docs\n"
6 | mvn javadoc:javadoc
7 | echo -e "Built docs at target/site/apidocs\n"
8 |
9 | echo -e "Checking out gh-pages branch\n"
10 | rm -rf gh-pages
11 | git clone --quiet --branch=gh-pages git@github.com:cognitect/transit-java.git gh-pages > /dev/null
12 | cd gh-pages
13 |
14 | echo -e "Replacing old gh-pages content with new docs\n"
15 | git rm -rf ./*
16 | cp -Rf ../target/site/apidocs/* ./
17 | git add -f .
18 | git commit -m "Updating gh-pages with new api docs"
19 | git push -fq origin gh-pages > /dev/null
20 | cd ..
21 |
22 | echo -e "Cleaning up\n"
23 | rm -rf gh-pages
24 |
25 |
--------------------------------------------------------------------------------
/build/package:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 |
5 | echo "Cleaning..."
6 | rm -rf ./target
7 |
8 | echo "Calculating version..."
9 | prefix=`cat VERSION_PREFIX`
10 | suffix=`build/revision`
11 | version=$prefix.$suffix
12 | echo $version
13 |
14 | target_name=transit-java-${version}
15 |
16 | echo "Packaging..."
17 | mvn versions:set -DnewVersion=${version}
18 | mvn install -DcreateChecksum=true
19 | mvn install:install-file -Dfile=./target/${target_name}.jar -DpomFile=pom.xml -DcreateChecksum=true -DlocalRepositoryPath=./target/package
20 | mvn versions:revert
21 |
22 | echo "Package done!"
23 |
--------------------------------------------------------------------------------
/build/release:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 |
5 | echo "Cleaning..."
6 | rm -rf ./target
7 |
8 | echo "Calculating version..."
9 | prefix=`cat VERSION_PREFIX`
10 | suffix=`build/revision`
11 | version=$prefix.$suffix
12 | echo $version
13 |
14 | target_name=transit-java-${version}
15 |
16 | echo "Releasing..."
17 | mvn versions:set -DnewVersion=${version}
18 | mvn clean deploy
19 | mvn versions:revert
20 |
21 | echo "Tagging..."
22 | git tag -a v${version} -m "Release ${version}"
23 | git push origin v${version}
24 |
25 | echo "Updating README.md versions"
26 | sed -i '' "s/[[:digit:]]\{1,2\}\.[[:digit:]]\{1,2\}\.[[:digit:]]\{2,4\}/${version}/g" README.md
27 | git commit -m "Update README.md with ${version}" README.md
28 | git push
29 |
30 | echo "Updating gh-pages with new api docs"
31 | build/doc
32 |
33 | echo "Release done!"
34 |
--------------------------------------------------------------------------------
/build/revision:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Returns the revision number used for deployment.
4 |
5 | set -e
6 |
7 | REVISION=`git --no-replace-objects describe --tags --match v0.0`
8 |
9 | # Extract the version number from the string. Do this in two steps so
10 | # it is a little easier to understand.
11 | REVISION=${REVISION:5} # drop the first 5 characters
12 | REVISION=${REVISION:0:${#REVISION}-9} # drop the last 9 characters
13 |
14 | echo $REVISION
15 |
--------------------------------------------------------------------------------
/deps.edn:
--------------------------------------------------------------------------------
1 | {:paths ["target/classes"]
2 | :deps
3 | {com.fasterxml.jackson.core/jackson-core {:mvn/version "2.8.7"}
4 | org.msgpack/msgpack {:mvn/version "0.6.12"}
5 | javax.xml.bind/jaxb-api {:mvn/version "2.3.0"}}
6 |
7 | :deps/prep-lib
8 | {:ensure "target/classes"
9 | :alias :build
10 | :fn compile}
11 |
12 | :aliases
13 | {:test
14 | {:extra-deps {junit/junit {:mvn/version "4.13.2"}}}
15 |
16 | :build
17 | {:deps {io.github.clojure/tools.build {:git/tag "v0.7.2" :git/sha "0361dde"}}
18 | :ns-default build}}}
19 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.cognitect
5 | transit-java
6 | jar
7 | dev
8 | transit-java
9 | Transit is a data format and a set of libraries for conveying values between applications written in different languages. This library provides support for marshalling Transit data to/from Java.
10 | http://github.com/cognitect/transit-java
11 |
12 |
13 | The Apache Software License, Version 2.0
14 | http://www.apache.org/licenses/LICENSE-2.0.txt
15 |
16 |
17 |
18 |
19 | Tim Ewald
20 | tim@cognitect.com
21 | Cognitect
22 | http://cognitect.com
23 |
24 |
25 |
26 | scm:git:git@github.com:cognitect/transit-java.git
27 | scm:git:git@github.com:cognitect/transit-java.git
28 | git@github.com:cognitect/transit-java.git
29 |
30 |
31 |
32 | junit
33 | junit
34 | 4.13.2
35 | test
36 |
37 |
38 | com.fasterxml.jackson.core
39 | jackson-core
40 | 2.14.2
41 |
42 |
43 | org.msgpack
44 | msgpack
45 | 0.6.12
46 |
47 |
48 | javax.xml.bind
49 | jaxb-api
50 | 2.4.0-b180830.0359
51 |
52 |
53 |
54 |
55 |
56 | org.apache.maven.plugins
57 | maven-compiler-plugin
58 | 3.8.1
59 |
60 | 1.8
61 | 1.8
62 | -Xlint:unchecked,rawtypes,removal
63 |
64 |
65 |
66 | org.codehaus.mojo
67 | versions-maven-plugin
68 | 2.8.1
69 |
70 |
71 | org.apache.maven.plugins
72 | maven-javadoc-plugin
73 | 3.3.1
74 |
75 |
76 | attach-javadocs
77 |
78 | jar
79 |
80 |
81 |
82 |
83 | com.cognitect.transit.impl
84 |
85 |
86 |
87 | org.apache.maven.plugins
88 | maven-source-plugin
89 | 3.2.1
90 |
91 |
92 | attach-sources
93 |
94 | jar-no-fork
95 |
96 |
97 |
98 |
99 |
100 | org.sonatype.plugins
101 | nexus-staging-maven-plugin
102 | 1.6.8
103 | true
104 |
105 | ossrh
106 | https://oss.sonatype.org/
107 | true
108 |
109 |
110 |
111 | org.apache.maven.plugins
112 | maven-gpg-plugin
113 | 3.0.1
114 |
115 |
116 | sign-artifacts
117 | verify
118 |
119 | sign
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/src/main/java/com/cognitect/transit/ArrayReadHandler.java:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Cognitect. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS-IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.cognitect.transit;
16 |
17 | /**
18 | * Provides an ArrayReader to Transit to use in incrementally parsing
19 | * an array representation of a value.
20 | */
21 | public interface ArrayReadHandler extends ReadHandler {
22 |
23 | /**
24 | * Provides an ArrayReader that a parser can use to convert
25 | * an array representation to an instance of a type incrementally
26 | * @return an ArrayReader
27 | */
28 | ArrayReader arrayReader();
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/cognitect/transit/ArrayReader.java:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Cognitect. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS-IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.cognitect.transit;
16 |
17 | public interface ArrayReader {
18 | /**
19 | * Initializes a new gestational result
20 | * @return a new gestational result
21 | */
22 | G init();
23 |
24 | /**
25 | * Initializes a new gestational result of specified size
26 | * @param size initial size of the new result
27 | * @return a new gestational result
28 | */
29 | G init(int size);
30 |
31 | /**
32 | * Adds an item to the result, returning
33 | * a new result; new result must be used for
34 | * any further invocations
35 | * @param a gestational result
36 | * @param item an item
37 | * @return a new result
38 | */
39 | G add(G a, T item);
40 |
41 | /**
42 | * Completes building of a result from a gestational result
43 | * @param ar the gestational result
44 | * @return the completed object
45 | */
46 | A complete(G ar);
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/cognitect/transit/DefaultReadHandler.java:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Cognitect. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS-IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.cognitect.transit;
16 |
17 | /**
18 | * Processes a non-decodable transit value
19 | */
20 | public interface DefaultReadHandler {
21 | /**
22 | * Reads a transit representation that cannot otherwise be read
23 | * @param tag the transit value's tag
24 | * @param rep the transit value's representation
25 | * @return the resulting generic object
26 | */
27 | T fromRep(String tag, Object rep);
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/cognitect/transit/Keyword.java:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Cognitect. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS-IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.cognitect.transit;
16 |
17 | /**
18 | * Represents a keyword
19 | * N.B. the strings returned by the Named interface for Keywords must be interned
20 | */
21 | public interface Keyword extends Comparable , Named{
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/cognitect/transit/Link.java:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Cognitect. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS-IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.cognitect.transit;
16 |
17 | /**
18 | * Represents a hypermedia link, as per http://amundsen.com/media-types/collection/format/#arrays-links
19 | */
20 | public interface Link {
21 | /**
22 | * Get the link's href
23 | * @return href
24 | */
25 | public URI getHref();
26 |
27 | /**
28 | * Get the link's rel
29 | * @return rel
30 | */
31 | public String getRel();
32 |
33 | /**
34 | * Get the link's name
35 | * @return name
36 | */
37 | public String getName();
38 |
39 | /**
40 | * Get the link's prompt
41 | * @return prompt
42 | */
43 | public String getPrompt();
44 |
45 | /**
46 | * Get the link's render semantic
47 | * @return render
48 | */
49 | public String getRender();
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/cognitect/transit/MapReadHandler.java:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Cognitect. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS-IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.cognitect.transit;
16 |
17 | /**
18 | * Provides a MapReader to Transit to use in incrementally parsing
19 | * a map representation of a value.
20 | */
21 | public interface MapReadHandler extends ReadHandler {
22 | /**
23 | * Provides a MapReader that a parser can use to convert
24 | * a map representation to an instance of a type incrementally
25 | * @return a MapReader
26 | */
27 | MapReader mapReader();
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/cognitect/transit/MapReader.java:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Cognitect. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS-IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.cognitect.transit;
16 |
17 | public interface MapReader {
18 | /**
19 | * Initializes a new (gestational) map
20 | * @return a new map
21 | */
22 | G init();
23 |
24 | /**
25 | * Initializes a new (gestational) map of specified size
26 | * @param size initial size of the new map
27 | * @return a new map
28 | */
29 | G init(int size);
30 |
31 | /**
32 | * Adds a key and value to the map, returning
33 | * a new map; new map must be used for
34 | * any further invocations
35 | * @param m a (gestational) map
36 | * @param key a key
37 | * @param val a value
38 | * @return a new gestational map
39 | */
40 | G add(G m, K key, V val);
41 |
42 | /**
43 | * Completes building of a map
44 | * @param m a map
45 | * @return the completed map
46 | */
47 | M complete(G m);
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/com/cognitect/transit/Named.java:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Rich Hickey. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS-IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.cognitect.transit;
16 |
17 | /**
18 | * Represents a namespace-scoped named object
19 | */
20 | public interface Named{
21 | /**
22 | * Gets the namespace
23 | * @return namespace
24 | */
25 | String getNamespace();
26 |
27 | /**
28 | * Gets the name
29 | * @return name
30 | */
31 | String getName();
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/cognitect/transit/Ratio.java:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Cognitect. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS-IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.cognitect.transit;
16 |
17 | import java.math.BigInteger;
18 |
19 | /**
20 | * Represents a ratio using BigIntegers
21 | */
22 | public interface Ratio extends Comparable {
23 | /**
24 | * The value of the ratio as double
25 | * @return a double
26 | */
27 | public Double getValue();
28 |
29 | /**
30 | * Gets the numerator
31 | * @return numerator
32 | */
33 | public BigInteger getNumerator();
34 |
35 | /**
36 | * Gets the denominator
37 | * @return denominator
38 | */
39 | public BigInteger getDenominator();
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/cognitect/transit/ReadHandler.java:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Cognitect. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS-IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.cognitect.transit;
16 |
17 | /** Converts a transit representation to an instance of a type; if type
18 | * implements ArrayReadHandler or MapReadHandler to support incremental
19 | * parsing of representation, that interface will be used instead
20 | */
21 | public interface ReadHandler {
22 | /**
23 | * Converts a transit value to an instance of a type
24 | * @param rep the transit value
25 | * @return the converted object
26 | */
27 | T fromRep(Rep rep);
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/cognitect/transit/Reader.java:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Cognitect. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS-IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.cognitect.transit;
16 |
17 | /**
18 | * Interface for reading values in transit format
19 | */
20 | public interface Reader {
21 | /**
22 | * Reads a single value from an input source
23 | * @return the value
24 | */
25 | T read();
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/cognitect/transit/SPI/ReaderSPI.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) Cognitect, Inc.
2 | // All rights reserved.
3 |
4 | package com.cognitect.transit.SPI;
5 |
6 | import com.cognitect.transit.ArrayReader;
7 | import com.cognitect.transit.MapReader;
8 | import com.cognitect.transit.Reader;
9 |
10 | import java.util.List;
11 | import java.util.Map;
12 |
13 | /**
14 | * Interface for providing custom MapReader and ArrayReader implementations for a Reader to use
15 | * when parsing native JSON or msgpack composite structures. This entry point exists to
16 | * enable Transit libraries for other JVM languages to layer on top of the Java Transit library,
17 | * but still get language-appropriate maps and arrays returned from a parse, while ensuring that
18 | * parsing and decoding work correctly. This interface should never be used by applications
19 | * that using this library.
20 | */
21 | public interface ReaderSPI {
22 | /**
23 | * Specifies a custom MapReader and ArrayReader to use when parsing native maps and arrays
24 | * in JSON or msgpack. Implementations must accept any type of input and must return a maps
25 | * or lists of any type of content. This function must be called before Reader.read is called.
26 | * @param mapBuilder a custom MapReader that produces a Map of objects to objects
27 | * @param listBuilder a custom ArrayReader that yields a List of objects
28 | * @return
29 | */
30 | public Reader setBuilders(MapReader, Map