├── docs
└── javadoc
│ ├── csv
│ └── 2.9
│ │ ├── package-list
│ │ ├── resources
│ │ ├── tab.gif
│ │ ├── titlebar.gif
│ │ ├── background.gif
│ │ └── titlebar_end.gif
│ │ ├── overview-frame.html
│ │ ├── com
│ │ └── fasterxml
│ │ │ └── jackson
│ │ │ └── dataformat
│ │ │ └── csv
│ │ │ ├── package-frame.html
│ │ │ └── impl
│ │ │ └── package-frame.html
│ │ └── index.html
│ ├── yaml
│ └── 2.9
│ │ ├── package-list
│ │ ├── resources
│ │ ├── tab.gif
│ │ ├── titlebar.gif
│ │ ├── background.gif
│ │ └── titlebar_end.gif
│ │ ├── overview-frame.html
│ │ ├── com
│ │ └── fasterxml
│ │ │ └── jackson
│ │ │ └── dataformat
│ │ │ └── yaml
│ │ │ ├── snakeyaml
│ │ │ └── error
│ │ │ │ └── package-frame.html
│ │ │ └── package-frame.html
│ │ ├── allclasses-noframe.html
│ │ ├── allclasses-frame.html
│ │ └── index.html
│ └── properties
│ └── 2.9
│ ├── resources
│ ├── tab.gif
│ ├── titlebar.gif
│ ├── background.gif
│ └── titlebar_end.gif
│ ├── package-list
│ ├── com
│ └── fasterxml
│ │ └── jackson
│ │ └── dataformat
│ │ └── javaprop
│ │ ├── impl
│ │ └── package-frame.html
│ │ ├── package-frame.html
│ │ ├── io
│ │ └── package-frame.html
│ │ └── util
│ │ └── package-frame.html
│ ├── overview-frame.html
│ └── index.html
├── csv
├── .gitattributes
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── META-INF
│ │ │ │ └── services
│ │ │ │ └── com.fasterxml.jackson.core.JsonFactory
│ │ └── java
│ │ │ └── com
│ │ │ └── fasterxml
│ │ │ └── jackson
│ │ │ └── dataformat
│ │ │ └── csv
│ │ │ ├── impl
│ │ │ ├── CsvIOContext.java
│ │ │ └── BufferedValue.java
│ │ │ ├── PackageVersion.java.in
│ │ │ └── CsvMappingException.java
│ └── test
│ │ └── java
│ │ ├── perf
│ │ ├── BogusOutputStream.java
│ │ ├── RequestEntry.java
│ │ └── F5500Reader.java
│ │ └── com
│ │ └── fasterxml
│ │ └── jackson
│ │ └── dataformat
│ │ └── csv
│ │ ├── failing
│ │ ├── MappingIteratorEnd119Test.java
│ │ ├── ParserQuotes19Test.java
│ │ ├── NullWriting116Test.java
│ │ └── SkipEmptyLines15Test.java
│ │ ├── schema
│ │ └── PropertyOrder74Test.java
│ │ ├── ser
│ │ ├── UnwrappedWriteTest.java
│ │ ├── TestGeneratorWithCustomSeparators.java
│ │ ├── SchemaReorderTest.java
│ │ ├── TestGeneratorWithSequences.java
│ │ ├── UnicodeWritingTest.java
│ │ ├── TestGeneratorNoSchema.java
│ │ ├── HeaderWriteTest.java
│ │ ├── ArrayWriteTest.java
│ │ ├── TestWriterWithMissingValues.java
│ │ ├── GeneratorIgnoreUnknown51Test.java
│ │ ├── MultipleWritesTest.java
│ │ └── FilteringTest.java
│ │ ├── FeaturesTest.java
│ │ ├── TestVersions.java
│ │ └── deser
│ │ ├── TrailingCommaTest.java
│ │ ├── TestParserStrictQuoting.java
│ │ ├── AnySetterTest.java
│ │ ├── IgnoreUnmappableTest.java
│ │ ├── TestParserEscapes.java
│ │ ├── TestParserWorkarounds.java
│ │ └── UnwrappingWithCSVTest.java
├── pom.xml
└── release-notes
│ └── CREDITS
├── yaml
├── .gitattributes
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── META-INF
│ │ │ │ ├── services
│ │ │ │ └── com.fasterxml.jackson.core.JsonFactory
│ │ │ │ ├── LICENSE
│ │ │ │ └── NOTICE
│ │ └── java
│ │ │ └── com
│ │ │ └── fasterxml
│ │ │ └── jackson
│ │ │ └── dataformat
│ │ │ └── yaml
│ │ │ ├── JacksonYAMLParseException.java
│ │ │ ├── snakeyaml
│ │ │ └── error
│ │ │ │ ├── package-info.java
│ │ │ │ ├── YAMLException.java
│ │ │ │ ├── Mark.java
│ │ │ │ └── MarkedYAMLException.java
│ │ │ ├── PackageVersion.java.in
│ │ │ └── YAMLFactoryBuilder.java
│ └── test
│ │ ├── resources
│ │ └── log4j.properties
│ │ └── java
│ │ └── com
│ │ └── fasterxml
│ │ └── jackson
│ │ └── dataformat
│ │ └── yaml
│ │ ├── failing
│ │ ├── CollectionReadTest.java
│ │ ├── GeratorWithMinimize50Test.java
│ │ └── ObjectIdTest.java
│ │ ├── ser
│ │ ├── BinaryWriteTest.java
│ │ ├── GeneratorWithSplitLinesTest.java
│ │ ├── GeneratorFeature34Test.java
│ │ ├── GeneratorFeatureTest.java
│ │ └── DatabindWriteTest.java
│ │ ├── ExceptionConversionTest.java
│ │ ├── deser
│ │ ├── UTF8ReaderTest.java
│ │ ├── BinaryReadTest.java
│ │ └── ParserDupHandlingTest.java
│ │ ├── TestVersions.java
│ │ ├── MultipleRootValuesTest.java
│ │ ├── PolymorphicIdTest.java
│ │ └── TypeIdTest.java
├── release-notes
│ └── CREDITS
├── README.md
└── pom.xml
├── properties
├── .gitattributes
├── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── fasterxml
│ │ │ │ └── jackson
│ │ │ │ └── dataformat
│ │ │ │ └── javaprop
│ │ │ │ ├── util
│ │ │ │ ├── package-info.java
│ │ │ │ ├── JPropNodeBuilder.java
│ │ │ │ └── Markers.java
│ │ │ │ ├── io
│ │ │ │ └── package-info.java
│ │ │ │ ├── PackageVersion.java.in
│ │ │ │ ├── JavaPropsFactoryBuilder.java
│ │ │ │ └── package-info.java
│ │ └── resources
│ │ │ └── META-INF
│ │ │ ├── LICENSE
│ │ │ ├── services
│ │ │ └── com.fasterxml.jackson.core.JsonFactory
│ │ │ └── NOTICE
│ └── test
│ │ └── java
│ │ └── com
│ │ └── fasterxml
│ │ └── jackson
│ │ └── dataformat
│ │ └── javaprop
│ │ ├── TestVersions.java
│ │ ├── util
│ │ └── JPropPathSplitterTest.java
│ │ ├── MapParsingTest.java
│ │ ├── CustomSeparatorsTest.java
│ │ ├── BinaryParsingTest.java
│ │ ├── SchemaConstructionTest.java
│ │ ├── GenerationEscapingTest.java
│ │ ├── PropertiesSupportTest.java
│ │ ├── DefaultConfigsTest.java
│ │ ├── SimpleParsingTest.java
│ │ ├── ArrayGenerationTest.java
│ │ └── SimpleGenerationTest.java
├── release-notes
│ ├── CREDITS
│ └── VERSION
└── pom.xml
├── .gitattributes
├── .gitignore
├── release-notes
├── CREDITS-old-properties.txt
├── CREDITS-2.x
├── CREDITS-old-yaml.txt
├── VERSION-2.x
└── CREDITS-old-csv.txt
├── README.md
├── .travis.yml
└── pom.xml
/docs/javadoc/csv/2.9/package-list:
--------------------------------------------------------------------------------
1 | com.fasterxml.jackson.dataformat.csv
2 | com.fasterxml.jackson.dataformat.csv.impl
3 |
--------------------------------------------------------------------------------
/csv/.gitattributes:
--------------------------------------------------------------------------------
1 | # Do not merge `pom.xml` from older version, as it will typically conflict
2 |
3 | pom.xml merge=ours
4 |
--------------------------------------------------------------------------------
/yaml/.gitattributes:
--------------------------------------------------------------------------------
1 | # Do not merge `pom.xml` from older version, as it will typically conflict
2 |
3 | pom.xml merge=ours
4 |
--------------------------------------------------------------------------------
/csv/src/main/resources/META-INF/services/com.fasterxml.jackson.core.JsonFactory:
--------------------------------------------------------------------------------
1 | com.fasterxml.jackson.dataformat.csv.CsvFactory
2 |
--------------------------------------------------------------------------------
/properties/.gitattributes:
--------------------------------------------------------------------------------
1 | # Do not merge `pom.xml` from older version, as it will typically conflict
2 |
3 | pom.xml merge=ours
4 |
--------------------------------------------------------------------------------
/docs/javadoc/yaml/2.9/package-list:
--------------------------------------------------------------------------------
1 | com.fasterxml.jackson.dataformat.yaml
2 | com.fasterxml.jackson.dataformat.yaml.snakeyaml.error
3 |
--------------------------------------------------------------------------------
/yaml/src/main/resources/META-INF/services/com.fasterxml.jackson.core.JsonFactory:
--------------------------------------------------------------------------------
1 | com.fasterxml.jackson.dataformat.yaml.YAMLFactory
2 |
--------------------------------------------------------------------------------
/docs/javadoc/csv/2.9/resources/tab.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlrx/jackson-dataformats-text/master/docs/javadoc/csv/2.9/resources/tab.gif
--------------------------------------------------------------------------------
/docs/javadoc/yaml/2.9/resources/tab.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlrx/jackson-dataformats-text/master/docs/javadoc/yaml/2.9/resources/tab.gif
--------------------------------------------------------------------------------
/docs/javadoc/csv/2.9/resources/titlebar.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlrx/jackson-dataformats-text/master/docs/javadoc/csv/2.9/resources/titlebar.gif
--------------------------------------------------------------------------------
/docs/javadoc/csv/2.9/resources/background.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlrx/jackson-dataformats-text/master/docs/javadoc/csv/2.9/resources/background.gif
--------------------------------------------------------------------------------
/docs/javadoc/properties/2.9/resources/tab.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlrx/jackson-dataformats-text/master/docs/javadoc/properties/2.9/resources/tab.gif
--------------------------------------------------------------------------------
/docs/javadoc/yaml/2.9/resources/titlebar.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlrx/jackson-dataformats-text/master/docs/javadoc/yaml/2.9/resources/titlebar.gif
--------------------------------------------------------------------------------
/docs/javadoc/csv/2.9/resources/titlebar_end.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlrx/jackson-dataformats-text/master/docs/javadoc/csv/2.9/resources/titlebar_end.gif
--------------------------------------------------------------------------------
/docs/javadoc/yaml/2.9/resources/background.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlrx/jackson-dataformats-text/master/docs/javadoc/yaml/2.9/resources/background.gif
--------------------------------------------------------------------------------
/docs/javadoc/yaml/2.9/resources/titlebar_end.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlrx/jackson-dataformats-text/master/docs/javadoc/yaml/2.9/resources/titlebar_end.gif
--------------------------------------------------------------------------------
/docs/javadoc/properties/2.9/resources/titlebar.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlrx/jackson-dataformats-text/master/docs/javadoc/properties/2.9/resources/titlebar.gif
--------------------------------------------------------------------------------
/docs/javadoc/properties/2.9/resources/background.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlrx/jackson-dataformats-text/master/docs/javadoc/properties/2.9/resources/background.gif
--------------------------------------------------------------------------------
/docs/javadoc/properties/2.9/resources/titlebar_end.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlrx/jackson-dataformats-text/master/docs/javadoc/properties/2.9/resources/titlebar_end.gif
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Do not merge `pom.xml` from older version, as it will typically conflict
2 |
3 | pom.xml merge=ours
4 | csv/pom.xml merge=ours
5 | properties/pom.xml merge=ours
6 | yaml/pom.xml merge=ours
7 |
--------------------------------------------------------------------------------
/docs/javadoc/properties/2.9/package-list:
--------------------------------------------------------------------------------
1 | com.fasterxml.jackson.dataformat.javaprop
2 | com.fasterxml.jackson.dataformat.javaprop.impl
3 | com.fasterxml.jackson.dataformat.javaprop.io
4 | com.fasterxml.jackson.dataformat.javaprop.util
5 |
--------------------------------------------------------------------------------
/properties/src/main/java/com/fasterxml/jackson/dataformat/javaprop/util/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | Helper classes for dealing with property key to structured path conversion.
3 | */
4 |
5 | package com.fasterxml.jackson.dataformat.javaprop.util;
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # use glob syntax.
2 | syntax: glob
3 | *.class
4 | *~
5 | *.bak
6 | *.off
7 | *.old
8 | .DS_Store
9 |
10 | # building
11 | target
12 |
13 | # Eclipse
14 | .classpath
15 | .project
16 | .settings
17 |
18 | # IDEA
19 | *.iml
20 | *.ipr
21 | *.iws
22 | .idea/
23 |
--------------------------------------------------------------------------------
/properties/src/main/java/com/fasterxml/jackson/dataformat/javaprop/io/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | Internal helper classes used for handling of input and out contexts and
3 | efficient reading/writing of Java Properties encoded content.
4 | */
5 |
6 | package com.fasterxml.jackson.dataformat.javaprop.io;
7 |
--------------------------------------------------------------------------------
/yaml/src/test/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | log4j.rootLogger=WARN, A1
2 |
3 | # A1 is set to be a ConsoleAppender.
4 | log4j.appender.A1=org.apache.log4j.ConsoleAppender
5 | log4j.appender.A1.Encoding=UTF-8
6 |
7 | # A1 uses PatternLayout.
8 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout
9 | log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
10 |
--------------------------------------------------------------------------------
/yaml/src/main/resources/META-INF/LICENSE:
--------------------------------------------------------------------------------
1 | This copy of Jackson JSON processor YAML module is licensed under the
2 | Apache (Software) License, version 2.0 ("the License").
3 | See the License for details about distribution rights, and the
4 | specific rights regarding derivate works.
5 |
6 | You may obtain a copy of the License at:
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
--------------------------------------------------------------------------------
/properties/src/main/resources/META-INF/LICENSE:
--------------------------------------------------------------------------------
1 | This copy of Jackson JSON processor databind module is licensed under the
2 | Apache (Software) License, version 2.0 ("the License").
3 | See the License for details about distribution rights, and the
4 | specific rights regarding derivate works.
5 |
6 | You may obtain a copy of the License at:
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
--------------------------------------------------------------------------------
/properties/release-notes/CREDITS:
--------------------------------------------------------------------------------
1 | Project: jackson-dataformat-properties
2 |
3 | Here are people who have contributed to development of this project:
4 | (version numbers in parenthesis indicate release in which the problem was fixed)
5 |
6 | Tatu Saloranta, tatu.saloranta@iki.fi: author
7 |
8 | Jordi Sola (someth2say@github)
9 |
10 | * Reported #6: Null-check for JPropNode byName map
11 | (2.8.8)
12 |
--------------------------------------------------------------------------------
/release-notes/CREDITS-old-properties.txt:
--------------------------------------------------------------------------------
1 | Project: jackson-dataformat-properties
2 |
3 | Here are people who have contributed to development of this project:
4 | (version numbers in parenthesis indicate release in which the problem was fixed)
5 |
6 | Tatu Saloranta, tatu.saloranta@iki.fi: author
7 |
8 | Jordi Sola (someth2say@github)
9 |
10 | * Reported #6: Null-check for JPropNode byName map
11 | (2.8.8)
12 |
--------------------------------------------------------------------------------
/yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/JacksonYAMLParseException.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml;
2 |
3 | import com.fasterxml.jackson.core.JsonParseException;
4 | import com.fasterxml.jackson.core.JsonParser;
5 |
6 | /**
7 | * @since 2.8
8 | */
9 | public class JacksonYAMLParseException extends JsonParseException
10 | {
11 | private static final long serialVersionUID = 1L;
12 |
13 | public JacksonYAMLParseException(JsonParser p, String msg, Exception e) {
14 | super(p, msg, e);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/csv/src/main/java/com/fasterxml/jackson/dataformat/csv/impl/CsvIOContext.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.impl;
2 |
3 | import com.fasterxml.jackson.core.io.IOContext;
4 | import com.fasterxml.jackson.core.util.BufferRecycler;
5 |
6 | public class CsvIOContext extends IOContext
7 | {
8 | public CsvIOContext(BufferRecycler br, Object sourceRef, boolean managedResource) {
9 | super(br, sourceRef, managedResource);
10 | }
11 |
12 | public TextBuffer csvTextBuffer() {
13 | return new TextBuffer(_bufferRecycler);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/csv/src/test/java/perf/BogusOutputStream.java:
--------------------------------------------------------------------------------
1 | package perf;
2 |
3 | import java.io.IOException;
4 | import java.io.OutputStream;
5 |
6 | public class BogusOutputStream extends OutputStream
7 | {
8 | protected int _bytes;
9 |
10 | @Override
11 | public void write(byte[] buf) { write(buf, 0, buf.length); }
12 | @Override
13 | public void write(byte[] buf, int offset, int len) {
14 | _bytes += len;
15 | }
16 |
17 | @Override
18 | public void write(int b) throws IOException {
19 | _bytes++;
20 | }
21 |
22 | public int length() { return _bytes; }
23 | }
24 |
--------------------------------------------------------------------------------
/yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/snakeyaml/error/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | Replacement for shaded-in package that Jackson versions up to and including 2.7
3 | had; with 2.8 (and later 2.x) we unfortunately fake to sort of fake formerly
4 | relocated types. This is needed to improve backwards compatibility with
5 | frameworks like DropWizard.
6 |
7 | New code based on Jackson 2.8 and later should NOT use types in this package
8 | but instead rely on {@link com.fasterxml.jackson.dataformat.yaml.JacksonYAMLParseException}
9 | */
10 |
11 | package com.fasterxml.jackson.dataformat.yaml.snakeyaml.error;
12 |
--------------------------------------------------------------------------------
/csv/src/main/java/com/fasterxml/jackson/dataformat/csv/PackageVersion.java.in:
--------------------------------------------------------------------------------
1 | package @package@;
2 |
3 | import com.fasterxml.jackson.core.Version;
4 | import com.fasterxml.jackson.core.Versioned;
5 | import com.fasterxml.jackson.core.util.VersionUtil;
6 |
7 | /**
8 | * Automatically generated from PackageVersion.java.in during
9 | * packageVersion-generate execution of maven-replacer-plugin in
10 | * pom.xml.
11 | */
12 | public final class PackageVersion implements Versioned {
13 | public final static Version VERSION = VersionUtil.parseVersion(
14 | "@projectversion@", "@projectgroupid@", "@projectartifactid@");
15 |
16 | @Override
17 | public Version version() {
18 | return VERSION;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/PackageVersion.java.in:
--------------------------------------------------------------------------------
1 | package @package@;
2 |
3 | import com.fasterxml.jackson.core.Version;
4 | import com.fasterxml.jackson.core.Versioned;
5 | import com.fasterxml.jackson.core.util.VersionUtil;
6 |
7 | /**
8 | * Automatically generated from PackageVersion.java.in during
9 | * packageVersion-generate execution of maven-replacer-plugin in
10 | * pom.xml.
11 | */
12 | public final class PackageVersion implements Versioned {
13 | public final static Version VERSION = VersionUtil.parseVersion(
14 | "@projectversion@", "@projectgroupid@", "@projectartifactid@");
15 |
16 | @Override
17 | public Version version() {
18 | return VERSION;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/properties/src/main/java/com/fasterxml/jackson/dataformat/javaprop/PackageVersion.java.in:
--------------------------------------------------------------------------------
1 | package @package@;
2 |
3 | import com.fasterxml.jackson.core.Version;
4 | import com.fasterxml.jackson.core.Versioned;
5 | import com.fasterxml.jackson.core.util.VersionUtil;
6 |
7 | /**
8 | * Automatically generated from PackageVersion.java.in during
9 | * packageVersion-generate execution of maven-replacer-plugin in
10 | * pom.xml.
11 | */
12 | public final class PackageVersion implements Versioned {
13 | public final static Version VERSION = VersionUtil.parseVersion(
14 | "@projectversion@", "@projectgroupid@", "@projectartifactid@");
15 |
16 | @Override
17 | public Version version() {
18 | return VERSION;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/properties/src/main/resources/META-INF/services/com.fasterxml.jackson.core.JsonFactory:
--------------------------------------------------------------------------------
1 | # Copyright 2012 FasterXML.com
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 | com.fasterxml.jackson.dataformat.javaprop.JavaPropsFactory
16 |
--------------------------------------------------------------------------------
/yaml/src/main/resources/META-INF/NOTICE:
--------------------------------------------------------------------------------
1 | # Jackson JSON processor
2 |
3 | Jackson is a high-performance, Free/Open Source JSON processing library.
4 | It was originally written by Tatu Saloranta (tatu.saloranta@iki.fi), and has
5 | been in development since 2007.
6 | It is currently developed by a community of developers, as well as supported
7 | commercially by FasterXML.com.
8 |
9 | ## Licensing
10 |
11 | Jackson core and extension components may be licensed under different licenses.
12 | To find the details that apply to this artifact see the accompanying LICENSE file.
13 | For more information, including possible other licensing options, contact
14 | FasterXML.com (http://fasterxml.com).
15 |
16 | ## Credits
17 |
18 | A list of contributors may be found from CREDITS file, which is included
19 | in some artifacts (usually source distributions); but is always available
20 | from the source code management (SCM) system project uses.
21 |
--------------------------------------------------------------------------------
/properties/src/main/java/com/fasterxml/jackson/dataformat/javaprop/JavaPropsFactoryBuilder.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.javaprop;
2 |
3 | import com.fasterxml.jackson.core.base.DecorableTSFactory.DecorableTSFBuilder;
4 |
5 | /**
6 | * {@link com.fasterxml.jackson.core.TokenStreamFactory.TSFBuilder}
7 | * implementation for constructing {@link JavaPropsFactory}
8 | * instances.
9 | *
10 | * @since 3.0
11 | */
12 | public class JavaPropsFactoryBuilder extends DecorableTSFBuilder
13 | {
14 | public JavaPropsFactoryBuilder() {
15 | super();
16 | }
17 |
18 | public JavaPropsFactoryBuilder(JavaPropsFactory base) {
19 | super(base);
20 | }
21 |
22 | @Override
23 | public JavaPropsFactory build() {
24 | // 28-Dec-2017, tatu: No special settings beyond base class ones, so:
25 | return new JavaPropsFactory(this);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/properties/src/main/resources/META-INF/NOTICE:
--------------------------------------------------------------------------------
1 | # Jackson JSON processor
2 |
3 | Jackson is a high-performance, Free/Open Source JSON processing library.
4 | It was originally written by Tatu Saloranta (tatu.saloranta@iki.fi), and has
5 | been in development since 2007.
6 | It is currently developed by a community of developers, as well as supported
7 | commercially by FasterXML.com.
8 |
9 | ## Licensing
10 |
11 | Jackson core and extension components may be licensed under different licenses.
12 | To find the details that apply to this artifact see the accompanying LICENSE file.
13 | For more information, including possible other licensing options, contact
14 | FasterXML.com (http://fasterxml.com).
15 |
16 | ## Credits
17 |
18 | A list of contributors may be found from CREDITS file, which is included
19 | in some artifacts (usually source distributions); but is always available
20 | from the source code management (SCM) system project uses.
21 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/failing/MappingIteratorEnd119Test.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.failing;
2 |
3 | import com.fasterxml.jackson.databind.*;
4 | import com.fasterxml.jackson.dataformat.csv.*;
5 |
6 | public class MappingIteratorEnd119Test extends ModuleTestBase
7 | {
8 | // for [dataformat-csv#119]
9 | public void testDefaultSimpleQuotes() throws Exception
10 | {
11 | CsvMapper mapper = mapperForCsv();
12 | MappingIterator it = mapper.readerFor(String[].class)
13 | .without(CsvParser.Feature.WRAP_AS_ARRAY)
14 | .readValues("\"te,st\"");
15 | assertTrue(it.hasNextValue());
16 | String[] row = it.nextValue();
17 | assertEquals(1, row.length);
18 | assertEquals("te,st", row[0]);
19 |
20 | assertFalse(it.hasNextValue());
21 | assertFalse(it.hasNext());
22 |
23 | it.close();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/properties/src/main/java/com/fasterxml/jackson/dataformat/javaprop/util/JPropNodeBuilder.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.javaprop.util;
2 |
3 | import java.util.Map;
4 | import java.util.Properties;
5 |
6 | import com.fasterxml.jackson.dataformat.javaprop.*;
7 |
8 | public class JPropNodeBuilder
9 | {
10 | public static JPropNode build(JavaPropsSchema schema,
11 | Properties props)
12 | {
13 | JPropNode root = new JPropNode();
14 | JPropPathSplitter splitter = schema.pathSplitter();
15 | for (Map.Entry,?> entry : props.entrySet()) {
16 | // these should be Strings; but due to possible "compromised" properties,
17 | // let's play safe, coerce if and as necessary
18 | String key = String.valueOf(entry.getKey());
19 | String value = String.valueOf(entry.getValue());
20 |
21 | splitter.splitAndAdd(root, key, value);
22 | }
23 | return root;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/release-notes/CREDITS-2.x:
--------------------------------------------------------------------------------
1 | Here are people who have contributed to the development of Jackson JSON processor
2 | text dataformats project, version 2.x
3 | (version numbers in brackets indicate release in which the problem was fixed)
4 |
5 | (note: for older credits, check out release notes for 1.x versions)
6 |
7 | Tatu Saloranta, tatu.saloranta@iki.fi: author
8 |
9 | Simone Locci (pimuzzo@github)
10 |
11 | * Reported #51 (csv): Set of custom objects with `IGNORE_UNKNOWN` brokes silently csv
12 | (2.9.3)
13 |
14 | Mike Kobit (mkobit@github.com)
15 |
16 | * Reported #65 (yaml): `YAMLParser` incorrectly handles numbers with underscores in them
17 | (2.9.4)
18 |
19 | Fabrice Delhoste (spifd@github)
20 |
21 | * Reported #74 (properties): `JavaPropsMapper` issue deserializing multiple byte array properties
22 | (2.9.5)
23 |
24 | Thomas Hauk (thauk-copperleaf@github)
25 |
26 | * Contibuted #84 (yaml): Add option to allow use of platform-linefeed
27 | (`YAMLGenerator.Feature.USE_PLATFORM_LINE_BREAKS`)
28 | (2.9.6)
29 |
--------------------------------------------------------------------------------
/properties/release-notes/VERSION:
--------------------------------------------------------------------------------
1 | Project: jackson-dataformat-properties
2 |
3 | ------------------------------------------------------------------------
4 | === Releases ===
5 | ------------------------------------------------------------------------
6 |
7 | 2.9.0 (not yet released)
8 |
9 | #1: Add convenience method(s) for reading System properties
10 | #3: Write into `Properties` instance (factory, mapper) using
11 | `JavaPropsMapper.writeValue()` with `Properties` and
12 | `JavaPropsMapper.writeValueAsProperties()`
13 | #4: Allow binding from `Properties` instance
14 |
15 | 2.8.8 (not yet released)
16 |
17 | #6: Null-check for JPropNode byName map
18 | (reported by Jordi S)
19 |
20 | 2.8.7 (21-Feb-2017)
21 | 2.8.6 (12-Jan-2017)
22 | 2.8.5 (14-Nov-2016)
23 | 2.8.4 (14-Oct-2016)
24 | 2.8.3 (17-Sep-2016)
25 | 2.8.2 (30-Aug-2016)
26 | 2.8.1 (20-Jul-2016)
27 |
28 | No changes since 2.8.0.
29 |
30 | 2.8.0 (04-Jul-2016)
31 |
32 | No changes since 2.7.
33 |
34 | 2.7.x:
35 |
36 | First experimental/prototype versions.
37 |
--------------------------------------------------------------------------------
/yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/snakeyaml/error/YAMLException.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml.snakeyaml.error;
2 |
3 | import com.fasterxml.jackson.core.JsonParser;
4 | import com.fasterxml.jackson.dataformat.yaml.JacksonYAMLParseException;
5 |
6 | /**
7 | * Replacement for formerly shaded exception type from SnakeYAML; included
8 | * in 2.8 solely for backwards compatibility: new code that relies on Jackson 2.8
9 | * and alter should NOT use this type but only base type {@link YAMLException}.
10 | *
11 | * @deprecated Since 2.8
12 | */
13 | @Deprecated
14 | public class YAMLException extends JacksonYAMLParseException
15 | {
16 | private static final long serialVersionUID = 1L;
17 |
18 | public YAMLException(JsonParser p,
19 | org.yaml.snakeyaml.error.YAMLException src) {
20 | super(p, src.getMessage(), src);
21 | }
22 |
23 | public static YAMLException from(JsonParser p,
24 | org.yaml.snakeyaml.error.YAMLException src) {
25 | return new YAMLException(p, src);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/docs/javadoc/csv/2.9/overview-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Overview List (Jackson-dataformat-CSV 2.9.0 API)
8 |
9 |
10 |
11 |
12 |
13 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/CollectionReadTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml.failing;
2 |
3 | import java.util.*;
4 |
5 | import com.fasterxml.jackson.databind.ObjectMapper;
6 | import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
7 | import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
8 |
9 | // for [dataformat-yaml#26]: not sure if it's an actual bug, but adding for now.
10 | public class CollectionReadTest extends ModuleTestBase
11 | {
12 | static class SetBean {
13 | public List sets;
14 | }
15 |
16 | public void testSet26() throws Exception
17 | {
18 | ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
19 | final String YAML = "---\n"
20 | +"sets: !!set\n"
21 | +" ? a\n"
22 | +" ? b\n";
23 | SetBean bean = mapper.readValue(YAML, SetBean.class);
24 | assertNotNull(bean);
25 | assertNotNull(bean.sets);
26 | assertEquals(2, bean.sets.size());
27 | assertEquals("b", bean.sets.get(1));
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/docs/javadoc/yaml/2.9/overview-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Overview List (Jackson-dataformat-YAML 2.9.0 API)
8 |
9 |
10 |
11 |
12 |
13 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/properties/src/test/java/com/fasterxml/jackson/dataformat/javaprop/TestVersions.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.javaprop;
2 |
3 | import java.io.*;
4 |
5 | import com.fasterxml.jackson.core.*;
6 | import com.fasterxml.jackson.databind.ObjectMapper;
7 |
8 | public class TestVersions extends ModuleTestBase
9 | {
10 | public void testMapperVersions() throws IOException
11 | {
12 | ObjectMapper mapper = mapperForProps();
13 | assertVersion(mapper.tokenStreamFactory());
14 | JavaPropsParser p = (JavaPropsParser) mapper.createParser("abc=foo");
15 | assertVersion(p);
16 | JsonGenerator gen = mapper.createGenerator(new ByteArrayOutputStream());
17 | assertVersion(gen);
18 | p.close();
19 | gen.close();
20 | }
21 |
22 | /*
23 | /**********************************************************
24 | /* Helper methods
25 | /**********************************************************
26 | */
27 |
28 | private void assertVersion(Versioned vers)
29 | {
30 | assertNotNull(vers);
31 | assertEquals(PackageVersion.VERSION, vers.version());
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/schema/PropertyOrder74Test.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.schema;
2 |
3 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4 |
5 | import com.fasterxml.jackson.dataformat.csv.CsvMapper;
6 | import com.fasterxml.jackson.dataformat.csv.CsvSchema;
7 | import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;
8 |
9 | // For [dataformat-csv#74]: problems applying default do-sort handling
10 | public class PropertyOrder74Test extends ModuleTestBase
11 | {
12 | static class Point {
13 | public int y;
14 | public int x;
15 | }
16 |
17 | @JsonPropertyOrder()
18 | public static class PointWithAnnotation extends Point {}
19 |
20 | private final CsvMapper MAPPER = new CsvMapper();
21 |
22 | public void testSchemaWithOrdering() throws Exception
23 | {
24 | CsvSchema schema1 = MAPPER.schemaFor(Point.class);
25 | CsvSchema schema2 = MAPPER.schemaFor(PointWithAnnotation.class);
26 |
27 | assertEquals(schema1.size(), schema2.size());
28 | assertEquals(schema1.column(0).getName(), schema2.column(0).getName());
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/BinaryWriteTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml.ser;
2 |
3 | import org.junit.Assert;
4 |
5 | import com.fasterxml.jackson.databind.*;
6 | import com.fasterxml.jackson.databind.node.JsonNodeType;
7 | import com.fasterxml.jackson.databind.node.ObjectNode;
8 | import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
9 |
10 | public class BinaryWriteTest extends ModuleTestBase
11 | {
12 | private final ObjectMapper MAPPER = newObjectMapper();
13 |
14 | public void testBinaryViaTree() throws Exception
15 | {
16 | byte[] srcPayload = new byte[] { 1, 2, 3, 4, 5 };
17 | ObjectNode root = MAPPER.createObjectNode();
18 | root.put("payload", srcPayload);
19 | String doc = MAPPER.writeValueAsString(root);
20 |
21 | // and read back
22 | final JsonNode bean = MAPPER.readTree(doc);
23 | final JsonNode data = bean.get("payload");
24 | assertNotNull(data);
25 | assertEquals(JsonNodeType.BINARY, data.getNodeType());
26 | final byte[] b = data.binaryValue();
27 | Assert.assertArrayEquals(srcPayload, b);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ser/UnwrappedWriteTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.ser;
2 |
3 | import com.fasterxml.jackson.annotation.*;
4 |
5 | import com.fasterxml.jackson.dataformat.csv.*;
6 |
7 | public class UnwrappedWriteTest extends ModuleTestBase
8 | {
9 | @JsonPropertyOrder({ "f1", "f2", "f3" })
10 | static class Inner {
11 | public String f1;
12 | public String f2;
13 | public String f3;
14 | }
15 |
16 | @JsonPropertyOrder({ "a", "inner" })
17 | static class Outer {
18 | public String a;
19 |
20 | @JsonUnwrapped
21 | public Inner inner = new Inner();
22 | }
23 |
24 | // for [dataformat-csv#125]
25 | public void testWriteUnwrapped() throws Exception
26 | {
27 | CsvMapper mapper = mapperForCsv();
28 |
29 | // Set null value to 'null'
30 | final CsvSchema schema = mapper.schemaFor(Outer.class).withNullValue("null");
31 |
32 | // Create an object. All the fields are NULLs
33 | String csv = mapper.writer(schema).writeValueAsString(new Outer());
34 | assertEquals("null,null,null,null", csv.trim());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ExceptionConversionTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml;
2 |
3 | /**
4 | * Tests to try to ensure that SnakeYAML exceptions are not leaked,
5 | * both because they are problematic on OSGi runtimes (depending on
6 | * whether shading is used) and because it is generally a bad idea
7 | * to leak implementation details.
8 | */
9 | public class ExceptionConversionTest extends ModuleTestBase
10 | {
11 | public void testSimpleParsingLeakage() throws Exception
12 | {
13 | YAMLMapper mapper = newObjectMapper();
14 | try {
15 | mapper.readTree("foo:\nbar: true\n baz: false");
16 | fail("Should not pass with invalid YAML");
17 | } catch (org.yaml.snakeyaml.scanner.ScannerException e) {
18 | fail("Internal exception type: "+e);
19 | } catch (JacksonYAMLParseException e) { // as of 2.8, this is the type to expect
20 | // (subtype of JsonParseException)
21 | verifyException(e, "mapping values are not allowed here");
22 | } catch (Exception e) {
23 | fail("Unknown exception: "+e);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/properties/src/test/java/com/fasterxml/jackson/dataformat/javaprop/util/JPropPathSplitterTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.javaprop.util;
2 |
3 | import com.fasterxml.jackson.dataformat.javaprop.JavaPropsSchema;
4 | import com.fasterxml.jackson.dataformat.javaprop.ModuleTestBase;
5 |
6 | public class JPropPathSplitterTest extends ModuleTestBase
7 | {
8 | public void testSplitters()
9 | {
10 | JPropPathSplitter sp = JPropPathSplitter.create(JavaPropsSchema.emptySchema());
11 | // by default we should be getting general-purpose one
12 | assertEquals(JPropPathSplitter.FullSplitter.class, sp.getClass());
13 |
14 | // but if disabling index:
15 | sp = JPropPathSplitter.create(JavaPropsSchema.emptySchema()
16 | .withoutIndexMarker());
17 | assertEquals(JPropPathSplitter.CharPathOnlySplitter.class, sp.getClass());
18 |
19 | // or, if disabling index and path
20 | sp = JPropPathSplitter.create(JavaPropsSchema.emptySchema()
21 | .withoutPathSeparator()
22 | .withoutIndexMarker());
23 | assertEquals(JPropPathSplitter.NonSplitting.class, sp.getClass());
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/GeratorWithMinimize50Test.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml.failing;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
7 | import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
8 | import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
9 | import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
10 |
11 | public class GeratorWithMinimize50Test extends ModuleTestBase
12 | {
13 | private final static YAMLMapper MINIM_MAPPER;
14 | static {
15 | YAMLFactory f = YAMLFactory.builder()
16 | .configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)
17 | .build();
18 | MINIM_MAPPER = new YAMLMapper(f);
19 | }
20 |
21 | // [dataformats-test#50]
22 | public void testEmptyStringWithMinimizeQuotes() throws Exception
23 | {
24 | Map content = new HashMap<>();
25 | content.put("key", "");
26 | String yaml = MINIM_MAPPER.writeValueAsString(content).trim();
27 |
28 | assertEquals("---\nkey: \"\"", yaml); // fails - actual output is "---\nkey:"
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/csv/src/test/java/perf/RequestEntry.java:
--------------------------------------------------------------------------------
1 | package perf;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 |
5 | public class RequestEntry
6 | {
7 | @JsonProperty("APP_ID") public long appId;
8 | @JsonProperty("USER_SCREEN_NAME") public String userScreenName;
9 | @JsonProperty("REPORTER_SCREEN_NAME") public String reportScreenName;
10 | @JsonProperty("EVENT_DATE") public String eventDate;
11 | @JsonProperty("HOST") public String host;
12 | @JsonProperty("PATH") public String path;
13 | @JsonProperty("USER_AGENT") public String userAgent;
14 | @JsonProperty("IP") public String ip;
15 | @JsonProperty("COOKIE") public String cookie;
16 | @JsonProperty("SUBDOMAIN") public String subdomain;
17 | @JsonProperty("REQUEST_METHOD") public String requestMethod; // or Enum
18 | @JsonProperty("TRACE") public String trace;
19 | @JsonProperty("REFERRER") public String referrer;
20 | @JsonProperty("RELOAD_COUNT") public int reloadCount;
21 | @JsonProperty("SESSION_ID") public String sessionId;
22 | @JsonProperty("ACTION") public String action;
23 | @JsonProperty("CONTENT") public String content;
24 | @JsonProperty("KILL_COUNT") public int killCount;
25 | @JsonProperty("ABUSE_TYPE") public String abuseType;
26 | }
27 |
--------------------------------------------------------------------------------
/csv/src/main/java/com/fasterxml/jackson/dataformat/csv/CsvMappingException.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv;
2 |
3 | import com.fasterxml.jackson.databind.JsonMappingException;
4 |
5 | /**
6 | * Format-specific exception used to indicate problems regarding handling of CSV
7 | * content above minimal decoding, based on {@link CsvSchema}.
8 | *
9 | * @since 2.9
10 | */
11 | public class CsvMappingException extends JsonMappingException
12 | {
13 | private static final long serialVersionUID = 1L;
14 |
15 | protected final CsvSchema _schema;
16 |
17 | public CsvMappingException(CsvParser p, String msg, CsvSchema schema) {
18 | super(p, msg);
19 | _schema = schema;
20 | }
21 |
22 | public CsvMappingException(CsvGenerator gen, String msg, CsvSchema schema) {
23 | super(gen, msg);
24 | _schema = schema;
25 | }
26 |
27 | public static CsvMappingException from(CsvParser p, String msg, CsvSchema schema) {
28 | return new CsvMappingException(p, msg, schema);
29 | }
30 |
31 | public static CsvMappingException from(CsvGenerator gen, String msg, CsvSchema schema) {
32 | return new CsvMappingException(gen, msg, schema);
33 | }
34 |
35 | public CsvSchema getSchema() {
36 | return _schema;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/properties/src/main/java/com/fasterxml/jackson/dataformat/javaprop/util/Markers.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.javaprop.util;
2 |
3 | /**
4 | * Simple value class for encapsulating a pair of start and end markers;
5 | * initially needed for index markers (like "[" and "]").
6 | */
7 | public class Markers
8 | {
9 | protected final String _start, _end;
10 |
11 | protected Markers(String start, String end) {
12 | if (start == null || start.isEmpty()) {
13 | throw new IllegalArgumentException("Missing 'start' value");
14 | }
15 | if (end == null || end.isEmpty()) {
16 | throw new IllegalArgumentException("Missing 'end' value");
17 | }
18 | _start = start;
19 | _end = end;
20 | }
21 |
22 | /**
23 | * Factory method for creating simple marker pair with given
24 | * start and end markers. Note that both are needed; neither may
25 | * be empty or null
26 | */
27 | public static Markers create(String start, String end) {
28 | return new Markers(start, end);
29 | }
30 |
31 | public String getStart() {
32 | return _start;
33 | }
34 |
35 | public String getEnd() {
36 | return _end;
37 | }
38 |
39 | // public StringBuilder appendIn(String)
40 | }
41 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/FeaturesTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv;
2 |
3 | import java.io.StringWriter;
4 |
5 | import com.fasterxml.jackson.core.JsonGenerator;
6 | import com.fasterxml.jackson.core.JsonParser;
7 |
8 | public class FeaturesTest extends ModuleTestBase
9 | {
10 | public void testFactoryFeatures() throws Exception
11 | {
12 | CsvMapper mapper = mapperForCsv();
13 | CsvFactory f = mapper.tokenStreamFactory();
14 | assertFalse(f.canHandleBinaryNatively());
15 | assertFalse(f.canUseCharArrays());
16 | assertTrue(f.canUseSchema(CsvSchema.emptySchema()));
17 |
18 | JsonParser p = mapper.createParser("");
19 | assertFalse(p.canReadObjectId());
20 | assertFalse(p.canReadTypeId());
21 | assertTrue(p.canUseSchema(CsvSchema.emptySchema()));
22 | p.close();
23 |
24 | JsonGenerator g = mapper.createGenerator(new StringWriter());
25 | assertFalse(g.canOmitFields());
26 | assertFalse(g.canWriteBinaryNatively());
27 | assertFalse(g.canWriteObjectId());
28 | assertFalse(g.canWriteTypeId());
29 | assertTrue(g.canWriteFormattedNumbers());
30 | assertTrue(g.canUseSchema(CsvSchema.emptySchema()));
31 | g.close();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/TestVersions.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv;
2 |
3 | import java.io.*;
4 |
5 | import com.fasterxml.jackson.core.*;
6 | import com.fasterxml.jackson.databind.MapperFeature;
7 |
8 | public class TestVersions extends ModuleTestBase
9 | {
10 | public void testMapperVersions() throws IOException
11 | {
12 | CsvMapper mapper = new CsvMapper();
13 | assertVersion(mapper.tokenStreamFactory());
14 | JsonParser p = mapper.createParser("abc");
15 | assertVersion(p);
16 | p.close();
17 | JsonGenerator g = mapper.createGenerator(new ByteArrayOutputStream());
18 | assertVersion(g);
19 | g.close();
20 | }
21 |
22 | // Mostly to verify #11
23 | public void testMapperDefaults()
24 | {
25 | CsvMapper mapper = new CsvMapper();
26 | assertTrue(mapper.isEnabled(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY));
27 | }
28 |
29 | /*
30 | /**********************************************************
31 | /* Helper methods
32 | /**********************************************************
33 | */
34 |
35 | private void assertVersion(Versioned vers)
36 | {
37 | assertEquals(PackageVersion.VERSION, vers.version());
38 | }
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/docs/javadoc/properties/2.9/com/fasterxml/jackson/dataformat/javaprop/impl/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | com.fasterxml.jackson.dataformat.javaprop.impl (Jackson-dataformat-Properties 2.9.0 API)
8 |
9 |
10 |
11 |
12 |
13 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/properties/src/test/java/com/fasterxml/jackson/dataformat/javaprop/MapParsingTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.javaprop;
2 |
3 | import java.util.Map;
4 |
5 | import com.fasterxml.jackson.databind.ObjectMapper;
6 |
7 | public class MapParsingTest extends ModuleTestBase
8 | {
9 | static class MapWrapper {
10 | public Map map;
11 | }
12 |
13 | private final ObjectMapper MAPPER = mapperForProps();
14 |
15 | /*
16 | /**********************************************************************
17 | /* Test methods
18 | /**********************************************************************
19 | */
20 |
21 | public void testMapWithBranch() throws Exception
22 | {
23 | // basically "extra" branch should become as first element, and
24 | // after that ordering by numeric value
25 | final String INPUT = "map=first\n"
26 | +"map.b=second\n"
27 | +"map.xyz=third\n"
28 | ;
29 | MapWrapper w = MAPPER.readValue(INPUT, MapWrapper.class);
30 | assertNotNull(w.map);
31 | assertEquals(3, w.map.size());
32 | assertEquals("first", w.map.get(""));
33 | assertEquals("second", w.map.get("b"));
34 | assertEquals("third", w.map.get("xyz"));
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/snakeyaml/error/Mark.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml.snakeyaml.error;
2 |
3 | /**
4 | * Placeholder for shaded org.yaml.snakeyaml.error.Mark
5 | *
6 | * @since 2.8 (as non-shaded); earlier shaded in
7 | *
8 | * @deprecated Should use basic {@link com.fasterxml.jackson.core.JsonLocation} instead
9 | */
10 | @Deprecated // since 2.8
11 | public class Mark
12 | {
13 | protected final org.yaml.snakeyaml.error.Mark _source;
14 |
15 | protected Mark(org.yaml.snakeyaml.error.Mark src) {
16 | _source = src;
17 | }
18 |
19 | public static Mark from(org.yaml.snakeyaml.error.Mark src) {
20 | return (src == null) ? null : new Mark(src);
21 | }
22 |
23 | public String getName() {
24 | return _source.getName();
25 | }
26 |
27 | public String get_snippet() {
28 | return _source.get_snippet();
29 | }
30 |
31 | public String get_snippet(int indent, int max_length) {
32 | return _source.get_snippet(indent, max_length);
33 | }
34 |
35 | public int getColumn() {
36 | return _source.getColumn();
37 | }
38 |
39 | public int getLine() {
40 | return _source.getLine();
41 | }
42 |
43 | public int getIndex() {
44 | return _source.getIndex();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ser/TestGeneratorWithCustomSeparators.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.ser;
2 |
3 | import com.fasterxml.jackson.dataformat.csv.CsvMapper;
4 | import com.fasterxml.jackson.dataformat.csv.CsvSchema;
5 | import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;
6 |
7 | public class TestGeneratorWithCustomSeparators extends ModuleTestBase
8 | {
9 | // #17
10 | public void testOtherSeparator() throws Exception
11 | {
12 | CsvMapper mapper = mapperForCsv();
13 | CsvSchema schema = mapper.schemaFor(FiveMinuteUser.class).withoutHeader().withColumnSeparator(';');
14 | FiveMinuteUser user = new FiveMinuteUser("Barbie", "Benton", false, Gender.FEMALE, null);
15 | String result = mapper.writer(schema).writeValueAsString(user);
16 | assertEquals("Barbie;Benton;FEMALE;false;\n", result);
17 | }
18 |
19 | public void testTSV() throws Exception
20 | {
21 | CsvMapper mapper = mapperForCsv();
22 | CsvSchema schema = mapper.schemaFor(FiveMinuteUser.class).withoutHeader().withColumnSeparator('\t');
23 | FiveMinuteUser user = new FiveMinuteUser("Barbie", "Benton", false, Gender.FEMALE, null);
24 | String result = mapper.writer(schema).writeValueAsString(user);
25 | assertEquals("Barbie\tBenton\tFEMALE\tfalse\t\n", result);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/properties/src/test/java/com/fasterxml/jackson/dataformat/javaprop/CustomSeparatorsTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.javaprop;
2 |
3 | import com.fasterxml.jackson.databind.ObjectMapper;
4 |
5 | public class CustomSeparatorsTest extends ModuleTestBase
6 | {
7 | private final ObjectMapper MAPPER = mapperForProps();
8 |
9 | public void testCustomPathSeparator() throws Exception
10 | {
11 | JavaPropsSchema schema = JavaPropsSchema.emptySchema()
12 | .withPathSeparator("->")
13 | ;
14 | String props = MAPPER.writer(schema)
15 | .writeValueAsString(
16 | new Rectangle(new Point(1, -2), new Point(5, 10)));
17 | assertEquals("topLeft->x=1\n"
18 | +"topLeft->y=-2\n"
19 | +"bottomRight->x=5\n"
20 | +"bottomRight->y=10\n"
21 | ,props);
22 |
23 | // and should come back as well, even with some white space sprinkled
24 | final String INPUT = "topLeft->x = 1\n"
25 | +"topLeft->y= -2\n"
26 | +"bottomRight->x =5\n"
27 | +"bottomRight->y = 10\n";
28 |
29 | Rectangle result = MAPPER.readerFor(Rectangle.class)
30 | .with(schema)
31 | .readValue(INPUT);
32 | assertEquals(10, result.bottomRight.y);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ser/SchemaReorderTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.ser;
2 |
3 | import java.util.Arrays;
4 |
5 | import com.fasterxml.jackson.dataformat.csv.CsvMapper;
6 | import com.fasterxml.jackson.dataformat.csv.CsvSchema;
7 | import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;
8 |
9 | public class SchemaReorderTest extends ModuleTestBase
10 | {
11 | // should work ok since CsvMapper forces alphabetic ordering as default:
12 | static class Reordered {
13 | public int a, b, c, d;
14 | }
15 |
16 | private final CsvMapper MAPPER = new CsvMapper();
17 |
18 | public void testSchemaWithOrdering() throws Exception
19 | {
20 | CsvSchema schema = MAPPER.schemaFor(Reordered.class);
21 | assertEquals(aposToQuotes("['a','b','c','d']"), schema.getColumnDesc());
22 | schema = schema.sortedBy("b", "c");
23 | assertEquals(aposToQuotes("['b','c','a','d']"), schema.getColumnDesc());
24 |
25 | Reordered value = new Reordered();
26 | value.a = 1;
27 | value.b = 2;
28 | value.c = 3;
29 | value.d = 4;
30 |
31 | schema = schema.withHeader();
32 | String csv = MAPPER.writer(schema).writeValueAsString(Arrays.asList(value));
33 | assertEquals("b,c,a,d\n2,3,1,4\n", csv);
34 |
35 | // _verifyLinks(schema);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/failing/ParserQuotes19Test.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.failing;
2 |
3 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4 |
5 | import com.fasterxml.jackson.dataformat.csv.*;
6 |
7 | // for [dataformat-csv#19]
8 | public class ParserQuotes19Test extends ModuleTestBase
9 | {
10 | @JsonPropertyOrder({"s1", "s2", "s3"})
11 | protected static class ThreeString {
12 | public String s1, s2, s3;
13 | }
14 |
15 | /*
16 | /**********************************************************************
17 | /* Test methods
18 | /**********************************************************************
19 | */
20 |
21 | // For #19: need to handle spaces outside quotes, even if not trimming?
22 | public void testSimpleQuotesWithSpaces() throws Exception
23 | {
24 | CsvMapper mapper = mapperForCsv();
25 | CsvSchema schema = mapper.schemaFor(ThreeString.class);
26 | ThreeString result = mapper.reader(schema).forType(ThreeString.class).readValue(
27 | "\"abc\" , \"def\", \"gh\" \n");
28 |
29 | // start by trailing space trimming (easiest one to work)
30 | assertEquals("abc", result.s1);
31 | // follow by leading space trimming
32 | assertEquals("def", result.s2);
33 | // and then both
34 | assertEquals("gh", result.s3);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/docs/javadoc/properties/2.9/overview-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Overview List (Jackson-dataformat-Properties 2.9.0 API)
8 |
9 |
10 |
11 |
12 |
13 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/UTF8ReaderTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml.deser;
2 |
3 | import org.junit.Test;
4 |
5 | import com.fasterxml.jackson.dataformat.yaml.UTF8Reader;
6 |
7 | import java.io.ByteArrayInputStream;
8 | import java.io.IOException;
9 | import java.io.InputStream;
10 | import java.nio.charset.StandardCharsets;
11 |
12 | import static org.junit.Assert.assertEquals;
13 |
14 | public class UTF8ReaderTest {
15 |
16 | @Test
17 | public void canUseMultipleUTF8ReadersInSameThread() throws IOException {
18 | String message = "we expect this message to be present after reading the contents of the reader out";
19 | InputStream expected = new ByteArrayInputStream(("." + message).getBytes(StandardCharsets.UTF_8));
20 | InputStream overwriter =
21 | new ByteArrayInputStream(".in older versions of Jackson, this overwrote it"
22 | .getBytes(StandardCharsets.UTF_8));
23 |
24 | char[] result = new char[message.length()];
25 |
26 | UTF8Reader utf8Reader = new UTF8Reader(expected, true);
27 | UTF8Reader badUtf8Reader = new UTF8Reader(overwriter, true);
28 |
29 | utf8Reader.read();
30 | badUtf8Reader.read();
31 |
32 | utf8Reader.read(result);
33 |
34 | assertEquals(message, new String(result));
35 |
36 | utf8Reader.close();
37 | badUtf8Reader.close();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorWithSplitLinesTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml.ser;
2 |
3 | import com.fasterxml.jackson.dataformat.yaml.*;
4 |
5 | public class GeneratorWithSplitLinesTest extends ModuleTestBase
6 | {
7 | public void testSplitLines() throws Exception
8 | {
9 | final String TEXT = "1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890";
10 | final String[] INPUT = new String[] { TEXT };
11 | YAMLFactory f = new YAMLFactory();
12 |
13 | // verify default settings
14 | assertTrue(f.isEnabled(YAMLGenerator.Feature.SPLIT_LINES));
15 |
16 | // and first write with splitting enabled
17 | YAMLMapper mapper = new YAMLMapper(f);
18 | String yaml = mapper.writeValueAsString(INPUT).trim();
19 |
20 | assertEquals("---\n" +
21 | "- \"1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890\\\n" +
22 | " \\ 1234567890\"",
23 | yaml);
24 |
25 | // and then with splitting disabled
26 | yaml = mapper.writer()
27 | .without(YAMLGenerator.Feature.SPLIT_LINES)
28 | .writeValueAsString(INPUT).trim();
29 | assertEquals("---\n" +
30 | "- \"1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890\"",
31 | yaml);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/failing/NullWriting116Test.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.failing;
2 |
3 | import java.io.StringWriter;
4 |
5 | import com.fasterxml.jackson.databind.*;
6 |
7 | import com.fasterxml.jackson.dataformat.csv.*;
8 |
9 | public class NullWriting116Test extends ModuleTestBase
10 | {
11 | private final CsvMapper csv = new CsvMapper();
12 |
13 | // [dataformat#116]
14 | public void testWithObjectArray() throws Exception
15 | {
16 | CsvSchema schema = CsvSchema.builder()
17 | .addColumn("a", CsvSchema.ColumnType.NUMBER)
18 | .addColumn("b", CsvSchema.ColumnType.NUMBER)
19 | .setUseHeader(true)
20 | .build();
21 | ObjectWriter writer = csv.writer(schema);
22 | StringWriter out = new StringWriter();
23 | SequenceWriter sequence = writer.writeValues(out);
24 |
25 | sequence.write(new Object[]{ 1, 2 });
26 | // sequence.write(new Object[]{ null, 2 });
27 | sequence.write(new Object[]{ null, null });
28 | sequence.write(new Object[]{ 1, null });
29 |
30 | sequence.close();
31 |
32 | //System.err.println("CSV:\n"+out);
33 | assertEquals("a,b\n" +
34 | "1,2\n" +
35 | // ",2\n" +
36 | ",\n" +
37 | "1,\n", out.toString());
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/docs/javadoc/yaml/2.9/com/fasterxml/jackson/dataformat/yaml/snakeyaml/error/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | com.fasterxml.jackson.dataformat.yaml.snakeyaml.error (Jackson-dataformat-YAML 2.9.0 API)
8 |
9 |
10 |
11 |
12 |
13 |
14 |
Classes
15 |
18 |
Exceptions
19 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/snakeyaml/error/MarkedYAMLException.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml.snakeyaml.error;
2 |
3 | import com.fasterxml.jackson.core.JsonParser;
4 |
5 | /**
6 | * Replacement for formerly shaded exception type from SnakeYAML; included
7 | * in 2.8 solely for backwards compatibility: new code that relies on Jackson 2.8
8 | * and alter should NOT use this type but only base type {@link YAMLException}.
9 | *
10 | * @deprecated Since 2.8
11 | */
12 | @Deprecated
13 | public class MarkedYAMLException extends YAMLException
14 | {
15 | private static final long serialVersionUID = 1L;
16 |
17 | protected final org.yaml.snakeyaml.error.MarkedYAMLException _source;
18 |
19 | protected MarkedYAMLException(JsonParser p,
20 | org.yaml.snakeyaml.error.MarkedYAMLException src) {
21 | super(p, src);
22 | _source = src;
23 | }
24 |
25 | public static MarkedYAMLException from(JsonParser p,
26 | org.yaml.snakeyaml.error.MarkedYAMLException src) {
27 | return new MarkedYAMLException(p, src);
28 | }
29 |
30 | public String getContext() {
31 | return _source.getContext();
32 | }
33 |
34 | public Mark getContextMark() {
35 | return Mark.from(_source.getContextMark());
36 | }
37 |
38 | public String getProblem() {
39 | return _source.getProblem();
40 | }
41 |
42 | public Mark getProblemMark() {
43 | return Mark.from(_source.getProblemMark());
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/TrailingCommaTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.deser;
2 |
3 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4 | import com.fasterxml.jackson.databind.JsonMappingException;
5 | import com.fasterxml.jackson.databind.MappingIterator;
6 | import com.fasterxml.jackson.dataformat.csv.CsvMapper;
7 | import com.fasterxml.jackson.dataformat.csv.CsvParser;
8 | import com.fasterxml.jackson.dataformat.csv.CsvSchema;
9 | import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;
10 |
11 | public class TrailingCommaTest extends ModuleTestBase {
12 | final CsvMapper MAPPER = mapperForCsv();
13 |
14 | @JsonPropertyOrder({ "a", "b" })
15 | static class StringPair {
16 | public String a, b;
17 | }
18 |
19 | public void testDisallowTrailingComma() throws Exception
20 | {
21 | final String INPUT = "s,t\nd,e,\n";
22 | final CsvSchema schema = MAPPER.schemaFor(StringPair.class);
23 |
24 | MappingIterator it = MAPPER.readerFor(StringPair.class)
25 | .with(schema)
26 | .without(CsvParser.Feature.ALLOW_TRAILING_COMMA)
27 | .readValues(INPUT);
28 |
29 | it.nextValue();
30 | try {
31 | it.nextValue();
32 | fail("Should not have passed");
33 | } catch (JsonMappingException e) {
34 | verifyException(e, "Too many entries: expected at most 2 (value #2 (0 chars) \"\")");
35 | }
36 |
37 | it.close();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/properties/src/test/java/com/fasterxml/jackson/dataformat/javaprop/BinaryParsingTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.javaprop;
2 |
3 | import static org.junit.Assert.assertArrayEquals;
4 |
5 | import java.nio.ByteBuffer;
6 | import java.util.Properties;
7 |
8 | public class BinaryParsingTest extends ModuleTestBase
9 | {
10 | // [dataformats-text#74]: problem with multiple binary fields
11 | static class MyBean {
12 | public byte[] a;
13 | public byte[] b;
14 | public ByteBuffer c;
15 |
16 | protected MyBean() { }
17 | public MyBean(boolean bogus) {
18 | a = new byte[] { 1 };
19 | b = new byte[] { 3, 28, 7 };
20 | c = ByteBuffer.wrap(new byte[] { 1, 2, 3, 4, 5, 67 });
21 | }
22 | }
23 |
24 | /*
25 | /**********************************************************************
26 | /* Test methods
27 | /**********************************************************************
28 | */
29 |
30 | private final JavaPropsMapper MAPPER = mapperForProps();
31 |
32 | // [dataformats-text#74]
33 | public void testMultipleBinaryFields() throws Exception
34 | {
35 | MyBean src = new MyBean(true);
36 | Properties props = MAPPER.writeValueAsProperties(src);
37 |
38 | MyBean result = MAPPER.readPropertiesAs(props, MyBean.class);
39 | assertArrayEquals(src.a, result.a);
40 | assertArrayEquals(src.b, result.b);
41 | ByteBuffer b1 = src.c;
42 | ByteBuffer b2 = result.c;
43 |
44 | assertEquals(b1, b2);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorFeature34Test.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml.ser;
2 |
3 | import java.util.Map;
4 |
5 | import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
6 | import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
7 | import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
8 |
9 | public class GeneratorFeature34Test extends ModuleTestBase
10 | {
11 | /*
12 | /**********************************************************
13 | /* Test methods
14 | /**********************************************************
15 | */
16 |
17 | // [dataformats-text#34]: busted indentation
18 | public void testArrayIndentation67() throws Exception
19 | {
20 | String yamlBefore = "---\n" +
21 | "tags:\n" +
22 | " - tag:\n" +
23 | " values:\n" +
24 | " - \"first\"\n" +
25 | " - \"second\"\n" +
26 | " name: \"Mathematics\"";
27 |
28 | YAMLMapper yamlMapper = new YAMLMapper();
29 | Map,?> stuff = yamlMapper
30 | .readValue(yamlBefore, Map.class);
31 | String yamlAfter = yamlMapper.writer()
32 | .with(YAMLGenerator.Feature.INDENT_ARRAYS)
33 | .writeValueAsString(stuff);
34 | // and do it again to ensure it is parseable (no need to be identical)
35 | Map,?> stuff2 = yamlMapper.readValue(yamlAfter, Map.class);
36 | assertNotNull(stuff2);
37 | assertEquals(stuff, stuff2);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/BinaryReadTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml.deser;
2 |
3 | import java.io.IOException;
4 | import java.util.Arrays;
5 |
6 | import org.junit.Assert;
7 |
8 | import com.fasterxml.jackson.databind.*;
9 | import com.fasterxml.jackson.databind.node.JsonNodeType;
10 | import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
11 |
12 | public class BinaryReadTest extends ModuleTestBase
13 | {
14 | private final ObjectMapper MAPPER = newObjectMapper();
15 |
16 | public void testBinaryViaTree() throws Exception
17 | {
18 | final String BASE64 = " R0lGODlhDAAMAIQAAP//9/X1\n"
19 | +" 7unp5WZmZgAAAOfn515eXvPz\n"
20 | +" 7Y6OjuDg4J+fn5OTk6enp56e\n"
21 | +" nmleECcgggoBADs=";
22 | final String DOC = String.format(
23 | "---\n"
24 | +"picture: !!binary |\n"
25 | +"%s\n", BASE64);
26 |
27 | JsonNode bean = null;
28 | try {
29 | bean = MAPPER.readTree(DOC);
30 | } catch (IOException e) {
31 | fail("Should have decoded properly, instead got "+e);
32 | }
33 | final JsonNode picture = bean.get("picture");
34 | assertNotNull(picture);
35 |
36 | assertEquals(JsonNodeType.BINARY, picture.getNodeType());
37 | final byte[] gif = picture.binaryValue();
38 | assertNotNull(gif);
39 | assertEquals(65, gif.length);
40 | final byte[] actualFileHeader = Arrays.copyOfRange(gif, 0, 6);
41 | final byte[] expectedFileHeader = new byte[]{'G', 'I', 'F', '8', '9', 'a'};
42 | Assert.assertArrayEquals(expectedFileHeader, actualFileHeader);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ser/TestGeneratorWithSequences.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.ser;
2 |
3 | import java.util.*;
4 |
5 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
6 | import com.fasterxml.jackson.dataformat.csv.CsvMapper;
7 | import com.fasterxml.jackson.dataformat.csv.CsvSchema;
8 | import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;
9 |
10 | public class TestGeneratorWithSequences extends ModuleTestBase
11 | {
12 | @JsonPropertyOrder({"x", "y"})
13 | protected static class Entry {
14 | public int x, y;
15 |
16 | public Entry() { }
17 | public Entry(int x, int y) {
18 | this.x = x;
19 | this.y = y;
20 | }
21 | }
22 |
23 | /*
24 | /**********************************************************************
25 | /* Test methods
26 | /**********************************************************************
27 | */
28 |
29 | /**
30 | * Verify that we should be able to just serialize sequences as is
31 | * because any "array" markers are all but ignored by generator.
32 | */
33 | public void testAsSequence() throws Exception
34 | {
35 | CsvMapper mapper = mapperForCsv();
36 | List entries = new ArrayList();
37 | entries.add(new Entry(1, 2));
38 | entries.add(new Entry(7, 8));
39 | CsvSchema schema = mapper.schemaFor(Entry.class)
40 | .withLineSeparator("\n");
41 | String csv = mapper.writer(schema)
42 | .writeValueAsString(entries);
43 | assertEquals("1,2\n7,8\n", csv);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/properties/src/test/java/com/fasterxml/jackson/dataformat/javaprop/SchemaConstructionTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.javaprop;
2 |
3 | public class SchemaConstructionTest extends ModuleTestBase
4 | {
5 | // Tests to verify stickiness of settings
6 | public void testMutantFactories()
7 | {
8 | JavaPropsSchema empty = JavaPropsSchema.emptySchema();
9 | JavaPropsSchema schema2;
10 |
11 | assertFalse(empty.writeIndexUsingMarkers());
12 |
13 | schema2 = empty.withFirstArrayOffset(1);
14 | assertEquals(1, schema2.firstArrayOffset());
15 | assertEquals(1, schema2.withFirstArrayOffset(1).firstArrayOffset());
16 |
17 | schema2 = empty.withPathSeparator("//");
18 | assertEquals("//", schema2.pathSeparator());
19 | assertEquals("//", schema2.withPathSeparator("//").pathSeparator());
20 | assertEquals("", schema2.withoutPathSeparator().pathSeparator());
21 | assertEquals("", schema2.withPathSeparator(null).pathSeparator());
22 |
23 | schema2 = empty.withLineIndentation(" ");
24 | assertEquals(" ", schema2.lineIndentation());
25 | assertEquals(" ", schema2.withLineIndentation(" ").lineIndentation());
26 |
27 | schema2 = empty.withHeader("");
28 | assertEquals("", schema2.header());
29 | assertEquals("", schema2.withHeader("").header());
30 |
31 | schema2 = empty.withLineEnding("\r");
32 | assertEquals("\r", schema2.lineEnding());
33 | assertEquals("\r", schema2.withLineEnding("\r").lineEnding());
34 |
35 | assertEquals("JavaProps", schema2.getSchemaType());
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/properties/src/main/java/com/fasterxml/jackson/dataformat/javaprop/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | Basic API types to use with this module:
3 |
4 | {@link com.fasterxml.jackson.dataformat.javaprop.JavaPropsFactory}
5 | is the {@link com.fasterxml.jackson.core.JsonFactory} implementation used to
6 | create Java Properties parsers and generators
7 | {@link com.fasterxml.jackson.dataformat.javaprop.JavaPropsGenerator}
8 | is the matching {@link com.fasterxml.jackson.core.JsonGenerator} implementation to use
9 |
10 | {@link com.fasterxml.jackson.dataformat.javaprop.JavaPropsParser}
11 | is the matching {@link com.fasterxml.jackson.core.JsonParser} implementation to use
12 |
13 |
14 | {@link com.fasterxml.jackson.dataformat.javaprop.JavaPropsMapper} is a convenience
15 | sub-class of {@link com.fasterxml.jackson.databind.ObjectMapper} that is both configured
16 | to use {@link com.fasterxml.jackson.dataformat.javaprop.JavaPropsFactory}, and
17 | adds additional methods for using alternate content sources and targets for improved
18 | interoperability with {@link java.util.Properties}, System Properties, and env properties
19 |
20 | {@link com.fasterxml.jackson.dataformat.javaprop.JavaPropsSchema} is the
21 | {@link com.fasterxml.jackson.core.FormatSchema} implementation to use with Java Properties
22 | and defines details of how flat Java Properties keys are mapped to structured names
23 | of logical properties, POJOs, as well as other variations within possible Properties
24 | file notation (like indentation, key/value separator, linefeed to use)
25 |
26 |
27 | */
28 |
29 | package com.fasterxml.jackson.dataformat.javaprop;
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Overview
2 |
3 | This is a multi-module umbrella project for [Jackson](../../../jackson)
4 | standard text-format dataformat backends.
5 |
6 | Dataformat backends are used to support format alternatives to JSON, supported
7 | by default. This is done by sub-classing Jackson core abstractions of:
8 |
9 | * All backends sub-class `JsonFactory`, which is factory for:
10 | * `JsonParser` for reading data (decoding data encoding in supported format)
11 | * `JsonGenerator` for writing data (encoding data using supported format)
12 | * Some backends sub-class `ObjectMapper` for additional support for databinding
13 |
14 |
15 | ## Textual formats included
16 |
17 | Currently included backends are:
18 |
19 | * [CSV](csv/)
20 | * [Properties](properties/)
21 | * [YAML](yaml/)
22 |
23 | Standard supported formats that are not yet included here (but are likely added
24 | in future) are:
25 |
26 | * [XML](../../../jackson-dataformat-xml)
27 |
28 | ## License
29 |
30 | All modules are licensed under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt).
31 |
32 | ## Status
33 |
34 | [](https://travis-ci.org/FasterXML/jackson-dataformats-text)
35 |
36 | ## Maven dependencies
37 |
38 | To use these format backends Maven-based projects, use following dependency:
39 |
40 | ```xml
41 |
42 | com.fasterxml.jackson.dataformat
43 | jackson-dataformat-[FORMAT]
44 | 2.9.0
45 |
46 | ```
47 |
48 | where `[FORMAT]` is one of supported modules (`csv`, `properties`, `yaml`)
49 |
50 | ## More
51 |
52 | See [Wiki](../../wiki) for more information (javadocs).
53 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ser/UnicodeWritingTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.ser;
2 |
3 | import java.io.ByteArrayOutputStream;
4 |
5 | import com.fasterxml.jackson.databind.*;
6 |
7 | import com.fasterxml.jackson.dataformat.csv.*;
8 |
9 | /**
10 | * Tests to try to see if Unicode writing, reading work as expected.
11 | */
12 | public class UnicodeWritingTest extends ModuleTestBase
13 | {
14 | /*
15 | /**********************************************************************
16 | /* Test methods
17 | /**********************************************************************
18 | */
19 |
20 | final CsvMapper MAPPER = mapperForCsv();
21 |
22 | public void testSimpleStringSequence() throws Exception
23 | {
24 | // 16-Mar-2017, tatu: Actually, this assumes that read/write defaults are the same,
25 | // and for real Unicode support, UTF-8 (or UTF-16). Whereas many CSV impls assume
26 | // Latin-1 default. Oh well. We'll go UTF-8 unless punched in the face.
27 |
28 | ByteArrayOutputStream bytes = new ByteArrayOutputStream();
29 | SequenceWriter w = MAPPER.writer()
30 | .writeValues(bytes);
31 | // turns out this writes 2 columns... fine
32 | final String STRING1 = "R\u00F6ck!";
33 | final String STRING2 = "Smile (\u263A)...";
34 | w.write(STRING1);
35 | w.write(STRING2);
36 | w.close();
37 | byte[] b = bytes.toByteArray();
38 |
39 | String[] stuff = MAPPER.readerFor(String[].class)
40 | .readValue(b);
41 | assertEquals(2, stuff.length);
42 | assertEquals(STRING1, stuff[0]);
43 | assertEquals(STRING2, stuff[1]);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/properties/src/test/java/com/fasterxml/jackson/dataformat/javaprop/GenerationEscapingTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.javaprop;
2 |
3 | import java.util.*;
4 |
5 | import com.fasterxml.jackson.databind.ObjectMapper;
6 |
7 | public class GenerationEscapingTest extends ModuleTestBase
8 | {
9 | private final ObjectMapper MAPPER = mapperForProps();
10 |
11 | public void testKeyEscaping() throws Exception
12 | {
13 | Map input = new HashMap<>();
14 | input.put("ns:key", "value");
15 | assertEquals("ns\\:key=value\n", MAPPER.writeValueAsString(input));
16 |
17 | input = new HashMap<>();
18 | input.put("combo key", "value");
19 | assertEquals("combo\\ key=value\n", MAPPER.writeValueAsString(input));
20 |
21 | input = new HashMap<>();
22 | input.put("combo\tkey", "value");
23 | assertEquals("combo\\tkey=value\n", MAPPER.writeValueAsString(input));
24 | }
25 |
26 | public void testValueEscaping() throws Exception
27 | {
28 | /*
29 | Properties props = new Properties();
30 | props.put("ns:key", "value:foo=faa");
31 | java.io.StringWriter sw = new java.io.StringWriter();
32 | props.store(sw, null);
33 | System.err.println("-> "+sw);
34 | */
35 |
36 | Map input = new HashMap<>();
37 | input.put("key", "tab:\tTAB!");
38 | assertEquals("key=tab:\\tTAB!\n", MAPPER.writeValueAsString(input));
39 |
40 | input = new HashMap<>();
41 | input.put("key", "NUL=\0...");
42 | assertEquals("key=NUL=\\u0000...\n", MAPPER.writeValueAsString(input));
43 |
44 | input = new HashMap<>();
45 | input.put("key", "multi\nline");
46 | assertEquals("key=multi\\nline\n", MAPPER.writeValueAsString(input));
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/docs/javadoc/properties/2.9/com/fasterxml/jackson/dataformat/javaprop/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | com.fasterxml.jackson.dataformat.javaprop (Jackson-dataformat-Properties 2.9.0 API)
8 |
9 |
10 |
11 |
12 |
13 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
3 | jdk:
4 | - openjdk8
5 | - oraclejdk9
6 |
7 | # whitelist
8 | branches:
9 | only:
10 | - master
11 | - "3.0"
12 |
13 | # Below this line is configuration for deploying to the Sonatype OSS repo
14 | # https://knowm.org/configure-travis-ci-to-deploy-snapshots/
15 | before_install: "git clone -b travis `git config --get remote.origin.url` target/travis"
16 | after_success: "mvn deploy --settings target/travis/settings.xml"
17 |
18 | env:
19 | global:
20 | - secure: "SwGExPDhEwniyRqp7mrOCHQEJHY2S6bPpD7khnQ0s6KCysuyepYnwcPSM4fddh0iNuoqL+0rNnIL910mIedohB3CPijY6669fSUg7GdFNKZCBnU2vCuh/E4qPMQjXvX8jEp5pnVScOsBR+U1x7Y3Tycz1/fqBCVm0TTtR8nlHNdI196RulU8w1upYdjGQ+0eXbfEmbNDz3T+Fxa26bgZrJnotZGh5u3RzSdbTK/wywJ9ss9XTft/lHIGxw9IQB8xyGDEn7Rc6Gm8aPWhKs04LiRdMVFn4HJG1zo7gN7OYz/DQInjJVoDC72KBnO+oSbdgmR2qY4bIdamex/uTmohKC1zYKKWnw5kdj217ISulu/ympzdCWAnQYskmNRMwqVPYysYXl+vUZlzaU3hga4bYt9atcFzRe9kO2hXBcqZMGe4Lx4b8x1BCJWJ7bVrmbHOtljb9Pvjx2Hdm5+nLFhrCcx9Jw8fURuPDJKWl4qiWMBkj2uqB7XGFFHzvLWpXA6HBXsEi0MVplFnMSVglcTOmzPEC8TeM1MSFA+3Iq/VoQVIH/VwMmVGWgA9JTouu4lyYaNyXwkzqAUARDhDI7SleJBQMXxi4dQ3vvseUlzkhtbesMj5yCXtZdy9/A3r9WniCmvSh3LRVKjippGotSQzja7LI4cZTn9HcgYypYJisZ8="
21 | - secure: "TFZTuG+lhXYh4rN+iDMBbngYLZkSDq4vcfu5d7oeuUkP2QvJpbS+mPwRmLiMeedb4r/9MAxkPih+5ki00BI2r+lL4N/3jQsoAIRWPfg9DemlfqJK9+UlWkxprprGtaRKy4naUKduSVf+1AuHUrgRWx7KUy5ThNOpGPr6YaYC0M3VLQsrHerfxj6pHLwKIp9d+ye/L1P+4IX0LyZEk8uypFC4pRl0k5mU2WkY4u4121xBrAFO9+UuukgSjLvkBYUrTDAMCApW7nJONF+DS3+XmGclundaSeDJ2Xqt++WaGNElCpc7nTfmkGcVlXlCgn5Q1QSfRxg5j4ogTyRFx1TZKEbDhtDgkagFEQv8hEAI5spQFnhyFDD12j8zjtNdxyq3xl1/UcZVQwqeRlEx7hMRBAiMzAp/Yhv/2O6wwT58nAwdMBuWOneNmh9AYzteSxrK25hLU4Ya7i3OiUGPBr87hvPJmzhyZKlkHHI3vv+M3hE0iYLgjWi432LplNygaSJL3f/6kpRo4i9KoZ3lhIxqSX/Hlk0eS0JcLt91NoVHCsX6o+m9o+uSNhf0Wawr89hSWtEy6kjQ4CZrtR+yUfcrOuL5wpIQpk0lJ9lqT7kaD2QcKXmuCEhmPC70JbzzvUebEaZZ14VlKBEJQEapltw7OqDfLbobWIDu/fandZ2X2Ys="
22 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/TestParserStrictQuoting.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.deser;
2 |
3 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4 | import com.fasterxml.jackson.dataformat.csv.*;
5 |
6 | // Tests for [dataformat-csv#26]
7 | public class TestParserStrictQuoting extends ModuleTestBase
8 | {
9 | @JsonPropertyOrder({"a", "b"})
10 | protected static class AB {
11 | public String a, b;
12 |
13 | public AB() { }
14 | public AB(String a, String b) {
15 | this.a = a;
16 | this.b = b;
17 | }
18 | }
19 |
20 | /*
21 | /**********************************************************************
22 | /* Test methods
23 | /**********************************************************************
24 | */
25 |
26 | public void testStrictQuoting() throws Exception
27 | {
28 | final String NUMS = "12345 6789";
29 | final String LONG = NUMS + NUMS + NUMS + NUMS; // 40 chars should do it
30 |
31 | CsvMapper mapper = mapperForCsv();
32 |
33 | assertFalse(mapper.tokenStreamFactory().isEnabled(CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING));
34 | CsvSchema schema = mapper.schemaFor(AB.class).withoutHeader();
35 |
36 | final AB input = new AB("x", LONG);
37 |
38 | // with non-strict, should quote
39 | String csv = mapper.writer(schema).writeValueAsString(input);
40 | assertEquals(aposToQuotes("x,'"+LONG+"'"), csv.trim());
41 |
42 | // should be possible to hot-swap
43 | // and with strict/optimal, no quoting
44 | csv = mapper.writer(schema)
45 | .with(CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING)
46 | .writeValueAsString(input);
47 | assertEquals(aposToQuotes("x,"+LONG), csv.trim());
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/docs/javadoc/properties/2.9/com/fasterxml/jackson/dataformat/javaprop/io/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | com.fasterxml.jackson.dataformat.javaprop.io (Jackson-dataformat-Properties 2.9.0 API)
8 |
9 |
10 |
11 |
12 |
13 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/TestVersions.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml;
2 |
3 | import java.io.*;
4 |
5 | import com.fasterxml.jackson.core.*;
6 |
7 | public class TestVersions extends ModuleTestBase
8 | {
9 | private final YAMLMapper MAPPER = newObjectMapper();
10 |
11 | @SuppressWarnings("resource")
12 | public void testMapperVersions() throws IOException
13 | {
14 | // assertVersion(MAPPER);
15 | assertVersion(MAPPER.tokenStreamFactory());
16 | JsonParser p = MAPPER.createParser("123");
17 | assertVersion(p);
18 | p.close();
19 | JsonGenerator gen = MAPPER.createGenerator(new ByteArrayOutputStream());
20 | assertVersion(gen);
21 | }
22 |
23 | @SuppressWarnings("resource")
24 | public void testDefaults() throws Exception
25 | {
26 | YAMLFactory f = MAPPER.tokenStreamFactory();
27 | assertFalse(f.canHandleBinaryNatively());
28 | assertFalse(f.canUseCharArrays());
29 |
30 | JsonParser p = MAPPER.createParser(new StringReader(""));
31 | assertTrue(p.canReadObjectId());
32 | assertTrue(p.canReadTypeId());
33 | p.close();
34 |
35 | JsonGenerator g = MAPPER.createGenerator(new StringWriter());
36 | assertTrue(g.canOmitFields());
37 | assertTrue(g.canWriteFormattedNumbers());
38 | assertTrue(g.canWriteObjectId());
39 | assertTrue(g.canWriteTypeId());
40 | assertFalse(g.canWriteBinaryNatively());
41 | // note: do not try to close it, no content, exception
42 | }
43 |
44 | /*
45 | /**********************************************************
46 | /* Helper methods
47 | /**********************************************************
48 | */
49 |
50 | private void assertVersion(Versioned vers)
51 | {
52 | assertEquals(PackageVersion.VERSION, vers.version());
53 | }
54 | }
55 |
56 |
--------------------------------------------------------------------------------
/properties/src/test/java/com/fasterxml/jackson/dataformat/javaprop/PropertiesSupportTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.javaprop;
2 |
3 | import java.util.*;
4 |
5 | /**
6 | * Tests for extended functionality to work with JDK `Properties` Object
7 | */
8 | public class PropertiesSupportTest extends ModuleTestBase
9 | {
10 | private final JavaPropsMapper MAPPER = mapperForProps();
11 |
12 | public void testSimpleEmployee() throws Exception
13 | {
14 | Properties props = new Properties();
15 | props.put("a.b", "14");
16 | props.put("x", "foo");
17 | Map,?> result = MAPPER.readPropertiesAs(props, Map.class);
18 | assertNotNull(result);
19 | assertEquals(2, result.size());
20 | assertEquals("foo", result.get("x"));
21 | Object ob = result.get("a");
22 | assertNotNull(ob);
23 | assertTrue(ob instanceof Map,?>);
24 | Map,?> m2 = (Map,?>) ob;
25 | assertEquals(1, m2.size());
26 | assertEquals("14", m2.get("b"));
27 | }
28 |
29 | public void testWithCustomSchema() throws Exception
30 | {
31 | Properties props = new Properties();
32 | props.put("a/b", "14");
33 | props.put("x.y/z", "foo");
34 | JavaPropsSchema schema = JavaPropsSchema.emptySchema()
35 | .withPathSeparator("/");
36 | Map,?> result = MAPPER.readPropertiesAs(props, schema,
37 | MAPPER.constructType(Map.class));
38 | assertNotNull(result);
39 | assertEquals(2, result.size());
40 | Object ob = result.get("a");
41 | assertNotNull(ob);
42 | assertTrue(ob instanceof Map,?>);
43 | Map,?> m2 = (Map,?>) ob;
44 | assertEquals(1, m2.size());
45 | assertEquals("14", m2.get("b"));
46 |
47 | ob = result.get("x.y");
48 | assertNotNull(ob);
49 | assertTrue(ob instanceof Map,?>);
50 | m2 = (Map,?>) ob;
51 | assertEquals(1, m2.size());
52 | assertEquals("foo", m2.get("z"));
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/properties/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | com.fasterxml.jackson.dataformat
6 | jackson-dataformats-text
7 | 3.0.0-SNAPSHOT
8 |
9 | jackson-dataformat-properties
10 | Jackson-dataformat-Properties
11 | bundle
12 | Support for reading and writing content of "Java Properties" style
13 | configuration files as if there was implied nesting structure (by default using dots as separators).
14 |
15 | http://github.com/FasterXML/jackson-dataformats-text
16 |
17 |
18 | com/fasterxml/jackson/dataformat/javaprop
19 | ${project.groupId}.javaprop
20 |
21 |
22 |
23 |
24 |
25 | com.fasterxml.jackson.core
26 | jackson-databind
27 | provided
28 |
29 |
30 |
31 | com.fasterxml.jackson.core
32 | jackson-annotations
33 | test
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | com.google.code.maven-replacer-plugin
42 | replacer
43 |
44 |
45 | process-packageVersion
46 | generate-sources
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/yaml/release-notes/CREDITS:
--------------------------------------------------------------------------------
1 | Here are people who have contributed to development Jackson JSON process
2 | databind core component, version 2.x
3 | (version numbers in brackets indicate release in which the problem was fixed)
4 |
5 | (note: for older credits, check out release notes for 1.x versions)
6 |
7 | Tatu Saloranta, tatu.saloranta@iki.fi: author
8 |
9 | Shawn Smith:
10 |
11 | - Contributed [Issue-14]: Fix parsing of longs near MIN/MAX_INT, parsing of BigIntegers.
12 | (2.1.4)
13 |
14 | Łukasz Dywicki
15 | - Fixed #19: Change build to avoid OSGi dep to SnakeYAML (which is instead shaded in)
16 | (2.5.0)
17 | - Contributed #14: Fix parsing of longs near MIN/MAX_INT, parsing of BigIntegers.
18 | (2.1.4)
19 |
20 | Benson Margulies (benson-basis@github)
21 |
22 | - Fixed #27: OSGI bundle does not work due to shading
23 | (2.4.4)
24 | - Reported #30: `YamlFactory.writeValue(File, Object)` busted
25 | (2.4.5)
26 | - Contributed #50: Lack of SnakeYAML Resolver leaves some missing features
27 | (2.7.0)
28 |
29 | Ville Koskela (vjkoskela@github)
30 |
31 | - Requested #35: Add `YAMLGenerator.Feature.SPLIT_LINES` to allow controlling whether
32 | SnakeYAML splits longer text blocks with line breaks or not.
33 | (2.6.0)
34 |
35 | Geoff Bourne (itzg@github)
36 |
37 | - Contributed #38: Add MINIMIZE_QUOTES generator feature
38 | (2.7.0)
39 |
40 | Sebastian Herold (heroldus@github)
41 |
42 | - Reported #69: Problem to parse time values as string
43 | (2.7.7)
44 |
45 | James Baker (j-baker@github)
46 |
47 | - Reported, contributed fix for #70: UTF8Reader is unsafe if a
48 | Jackson-annotated class itself deserialises a Jackson-annotated class
49 | (2.7.8)
50 |
51 | Tanguy Leroux (tlrx@github)
52 |
53 | - Reported, contributed test, fix for #80: Fix UTF8Writer when used in same thread
54 | (2.7.9)
55 |
56 | Preston Gilchrist (prestongilchrist@github)
57 |
58 | - Contributed #65: Feature.MINIMIZE_QUOTES needs to write numbers as strings with quotes
59 | (2.8.2)
60 |
61 | Roland Huss (rhuss@github)
62 |
63 | - Reported #77, contributed fix: Boolean-like content of string must never be unquoted
64 | (2.8.4)
65 | - Contributed #76: Add `YAMLGenerator.Feature.LITERAL_BLOCK_STYLE` for String output
66 | (2.9.0)
67 |
--------------------------------------------------------------------------------
/release-notes/CREDITS-old-yaml.txt:
--------------------------------------------------------------------------------
1 | Here are people who have contributed to development Jackson JSON process
2 | databind core component, version 2.x
3 | (version numbers in brackets indicate release in which the problem was fixed)
4 |
5 | (note: for older credits, check out release notes for 1.x versions)
6 |
7 | Tatu Saloranta, tatu.saloranta@iki.fi: author
8 |
9 | Shawn Smith:
10 |
11 | - Contributed [Issue-14]: Fix parsing of longs near MIN/MAX_INT, parsing of BigIntegers.
12 | (2.1.4)
13 |
14 | Łukasz Dywicki
15 | - Fixed #19: Change build to avoid OSGi dep to SnakeYAML (which is instead shaded in)
16 | (2.5.0)
17 | - Contributed #14: Fix parsing of longs near MIN/MAX_INT, parsing of BigIntegers.
18 | (2.1.4)
19 |
20 | Benson Margulies (benson-basis@github)
21 |
22 | - Fixed #27: OSGI bundle does not work due to shading
23 | (2.4.4)
24 | - Reported #30: `YamlFactory.writeValue(File, Object)` busted
25 | (2.4.5)
26 | - Contributed #50: Lack of SnakeYAML Resolver leaves some missing features
27 | (2.7.0)
28 |
29 | Ville Koskela (vjkoskela@github)
30 |
31 | - Requested #35: Add `YAMLGenerator.Feature.SPLIT_LINES` to allow controlling whether
32 | SnakeYAML splits longer text blocks with line breaks or not.
33 | (2.6.0)
34 |
35 | Geoff Bourne (itzg@github)
36 |
37 | - Contributed #38: Add MINIMIZE_QUOTES generator feature
38 | (2.7.0)
39 |
40 | Sebastian Herold (heroldus@github)
41 |
42 | - Reported #69: Problem to parse time values as string
43 | (2.7.7)
44 |
45 | James Baker (j-baker@github)
46 |
47 | - Reported, contributed fix for #70: UTF8Reader is unsafe if a
48 | Jackson-annotated class itself deserialises a Jackson-annotated class
49 | (2.7.8)
50 |
51 | Tanguy Leroux (tlrx@github)
52 |
53 | - Reported, contributed test, fix for #80: Fix UTF8Writer when used in same thread
54 | (2.7.9)
55 |
56 | Preston Gilchrist (prestongilchrist@github)
57 |
58 | - Contributed #65: Feature.MINIMIZE_QUOTES needs to write numbers as strings with quotes
59 | (2.8.2)
60 |
61 | Roland Huss (rhuss@github)
62 |
63 | - Reported #77, contributed fix: Boolean-like content of string must never be unquoted
64 | (2.8.4)
65 | - Contributed #76: Add `YAMLGenerator.Feature.LITERAL_BLOCK_STYLE` for String output
66 | (2.9.0)
67 |
--------------------------------------------------------------------------------
/csv/src/test/java/perf/F5500Reader.java:
--------------------------------------------------------------------------------
1 | package perf;
2 |
3 | import java.io.*;
4 | import java.util.*;
5 |
6 | import com.fasterxml.jackson.databind.MappingIterator;
7 |
8 | import com.fasterxml.jackson.dataformat.csv.CsvMapper;
9 | import com.fasterxml.jackson.dataformat.csv.CsvSchema;
10 |
11 | /**
12 | * Manual test for checking how fast a F-5500 file
13 | * (from http:///www.dol.gov/) can be read from a file
14 | */
15 | public final class F5500Reader
16 | {
17 | public static void main(String[] args) throws Exception
18 | {
19 | if (args.length != 1) {
20 | System.err.println("Usage: java .... [input file]");
21 | System.exit(1);
22 | }
23 | new F5500Reader().read(new File(args[0]));
24 | }
25 |
26 | private void read(File inputFile) throws IOException, InterruptedException
27 | {
28 | int x = 1;
29 | while (true) {
30 | Class> cls = ((x & 1) == 0) ? Map.class : F5500Entry.class;
31 | ++x;
32 | long now = System.currentTimeMillis();
33 | int count = readAll(inputFile, cls);
34 | long time = System.currentTimeMillis() - now;
35 | System.out.printf("DONE! Read %d rows as %s in %.1f seconds.\n",
36 | count, cls.getName(), time / 1000.0);
37 | Thread.sleep(500L);
38 | }
39 | }
40 |
41 | private int readAll(File inputFile, Class cls) throws IOException
42 | {
43 | System.out.print("Reading input as "+cls.getName()+" instances: ");
44 |
45 | int count = 0;
46 | CsvMapper mapper = new CsvMapper();
47 | CsvSchema schema = CsvSchema.builder()
48 | .setUseHeader(true)
49 | .build();
50 |
51 | MappingIterator it = mapper.readerFor(cls)
52 | .with(schema).readValues(inputFile);
53 | while (it.hasNext()) {
54 | @SuppressWarnings("unused")
55 | T row = it.nextValue();
56 | ++count;
57 | if ((count & 0x3FFF) == 0) {
58 | System.out.print('.');
59 | }
60 | }
61 | System.out.println();
62 | it.close();
63 | return count;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/MultipleRootValuesTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml;
2 |
3 | import java.util.Map;
4 |
5 | import com.fasterxml.jackson.core.*;
6 | import com.fasterxml.jackson.core.type.TypeReference;
7 |
8 | import com.fasterxml.jackson.databind.MappingIterator;
9 |
10 | public class MultipleRootValuesTest extends ModuleTestBase
11 | {
12 | private final YAMLMapper MAPPER = new YAMLMapper();
13 |
14 | public void testMultipleDocumentsViaParser() throws Exception
15 | {
16 | final String YAML = "num: 42\n"
17 | +"---\n"
18 | +"num: -42"
19 | ;
20 | JsonParser p = MAPPER.createParser(YAML);
21 | assertToken(JsonToken.START_OBJECT, p.nextToken());
22 | assertToken(JsonToken.FIELD_NAME, p.nextToken());
23 | assertEquals("num", p.currentName());
24 | assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
25 | assertEquals(42, p.getIntValue());
26 | assertEquals(JsonParser.NumberType.INT, p.getNumberType());
27 | assertEquals("42", p.getText());
28 | assertToken(JsonToken.END_OBJECT, p.nextToken());
29 | assertToken(JsonToken.START_OBJECT, p.nextToken());
30 | assertToken(JsonToken.FIELD_NAME, p.nextToken());
31 | assertEquals("num", p.currentName());
32 | assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
33 | assertEquals(-42, p.getIntValue());
34 | assertEquals(JsonParser.NumberType.INT, p.getNumberType());
35 | assertEquals("-42", p.getText());
36 | assertToken(JsonToken.END_OBJECT, p.nextToken());
37 | p.close();
38 | }
39 |
40 | public void testMultipleDocumentsViaIterator() throws Exception
41 | {
42 | final String YAML = "num: 42\n"
43 | +"---\n"
44 | +"num: -42"
45 | ;
46 | MappingIterator> it = MAPPER.readerFor(new TypeReference>() {
47 | }).readValues(YAML);
48 |
49 | assertEquals(42, it.nextValue().get("num").intValue());
50 | assertEquals(-42, it.nextValue().get("num").intValue());
51 | it.close();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorFeatureTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml.ser;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | import com.fasterxml.jackson.databind.ObjectMapper;
7 | import com.fasterxml.jackson.databind.ObjectWriter;
8 | import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
9 | import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
10 |
11 | public class GeneratorFeatureTest extends ModuleTestBase
12 | {
13 | static class Words {
14 | public List words;
15 |
16 | public Words(String... w) {
17 | words = Arrays.asList(w);
18 | }
19 | }
20 |
21 | /*
22 | /**********************************************************
23 | /* Test methods
24 | /**********************************************************
25 | */
26 |
27 | private final ObjectMapper MAPPER = newObjectMapper();
28 |
29 | public void testArrayIndentation() throws Exception
30 | {
31 | Words input = new Words("first", "second", "third");
32 | // First: default settings, no indentation:
33 | String yaml = MAPPER.writeValueAsString(input);
34 | if (yaml.startsWith("---")) {
35 | yaml = yaml.substring(3);
36 | }
37 | yaml = yaml.trim();
38 | assertEquals("words:\n- \"first\"\n- \"second\"\n- \"third\"", yaml);
39 |
40 | // and then with different config
41 | ObjectWriter w = MAPPER.writer().with(YAMLGenerator.Feature.INDENT_ARRAYS);
42 |
43 | yaml = w.writeValueAsString(input);
44 | if (yaml.startsWith("---")) {
45 | yaml = yaml.substring(3);
46 | }
47 | yaml = yaml.trim();
48 | // Due to [dataformats-text#34], exact indentation amounts may vary
49 | // assertEquals("words:\n - \"first\"\n - \"second\"\n - \"third\"", yaml);
50 | String[] parts = yaml.split("\n");
51 | assertEquals(4, parts.length);
52 | assertEquals("words:", parts[0].trim());
53 | assertEquals("- \"first\"", parts[1].trim());
54 | assertEquals("- \"second\"", parts[2].trim());
55 | assertEquals("- \"third\"", parts[3].trim());
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/AnySetterTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.deser;
2 |
3 | import java.util.*;
4 |
5 | import com.fasterxml.jackson.annotation.JsonAnySetter;
6 | import com.fasterxml.jackson.dataformat.csv.*;
7 |
8 | public class AnySetterTest extends ModuleTestBase
9 | {
10 | static class Entry {
11 | Map stuff = new LinkedHashMap();
12 |
13 | public int age;
14 | public String name;
15 |
16 | @JsonAnySetter
17 | public void set(String key, Object value) {
18 | // for secondary test, where name remains empty:
19 | if (key.isEmpty()) {
20 | key = String.valueOf(stuff.size());
21 | }
22 | stuff.put(key, value);
23 | }
24 | }
25 |
26 | /*
27 | /**********************************************************************
28 | /* Test methods
29 | /**********************************************************************
30 | */
31 |
32 | public void testSimpleHeader() throws Exception
33 | {
34 | CsvMapper mapper = mapperForCsv();
35 | CsvSchema schema = CsvSchema.emptySchema().withHeader();
36 | Entry entry = mapper.readerFor(Entry.class).with(schema).readValue(
37 | "name,age,gender,extra\nBarbara,35,F,1246\n");
38 | assertEquals(35, entry.age);
39 | assertEquals("F", entry.stuff.get("gender"));
40 | assertEquals("1246", entry.stuff.get("extra"));
41 | assertEquals(2, entry.stuff.size());
42 | }
43 |
44 | // [dataformat-csv@109]: allow "any-setter-like"
45 | public void testWithMapToAny() throws Exception
46 | {
47 | CsvMapper mapper = mapperForCsv();
48 | CsvSchema schema = CsvSchema.emptySchema().withHeader()
49 | .withAnyPropertyName("");
50 | Entry entry = mapper.readerFor(Entry.class).with(schema)
51 | .readValue("name,age\nJoe,28,first,second\n");
52 | assertEquals("Joe", entry.name);
53 | assertEquals(28, entry.age);
54 | assertEquals("first", entry.stuff.get("0"));
55 | assertEquals("second", entry.stuff.get("1"));
56 | assertEquals(2, entry.stuff.size());
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/yaml/README.md:
--------------------------------------------------------------------------------
1 | # Overview
2 |
3 | This project contains [Jackson](../../../../jackson) extension component for reading and writing [YAML](http://en.wikipedia.org/wiki/YAML) encoded data.
4 | [SnakeYAML](https://bitbucket.org/asomov/snakeyaml/) library is used for low-level YAML parsing.
5 | This project adds necessary abstractions on top to make things work with other Jackson functionality.
6 |
7 | Project is licensed under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt).
8 |
9 | # Status
10 |
11 | [](https://travis-ci.org/FasterXML/jackson-dataformat-yaml)
12 | [](https://maven-badges.herokuapp.com/maven-central/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml/)
13 | [](http://www.javadoc.io/doc/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml)
14 |
15 | Module has been production ready since version 2.5.
16 |
17 | ## Maven dependency
18 |
19 | To use this extension on Maven-based projects, use following dependency:
20 |
21 | ```xml
22 |
23 | com.fasterxml.jackson.dataformat
24 | jackson-dataformat-yaml
25 | 2.9.2
26 |
27 | ```
28 |
29 | # Usage
30 |
31 | ## Simple usage
32 |
33 | Usage is as with basic `JsonFactory`; most commonly you will just construct a standard `ObjectMapper` with `com.fasterxml.jackson.dataformat.yaml.YAMLFactory`, like so:
34 |
35 | ```java
36 | ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
37 | User user = mapper.readValue(yamlSource, User.class);
38 | ```
39 |
40 | but you can also just use underlying `YAMLFactory` and parser it produces, for event-based processing:
41 |
42 | ```java
43 | YAMLFactory factory = new YAMLFactory();
44 | JsonParser parser = factory.createJsonParser(yamlString); // don't be fooled by method name...
45 | while (parser.nextToken() != null) {
46 | // do something!
47 | }
48 | ```
49 |
50 | # Documentation
51 |
52 | * [Wiki](../../../wiki) contains links to Javadocs, external documentation
53 |
--------------------------------------------------------------------------------
/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/ObjectIdTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml.failing;
2 |
3 | import com.fasterxml.jackson.annotation.*;
4 | import com.fasterxml.jackson.databind.JsonNode;
5 | import com.fasterxml.jackson.databind.ObjectMapper;
6 |
7 | import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
8 |
9 | /**
10 | * Although native Object Ids work in general, Tree Model currently
11 | * has issues with it (see [dataformat-yaml#24])
12 | */
13 | public class ObjectIdTest extends ModuleTestBase
14 | {
15 | @JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id")
16 | static class Node
17 | {
18 | public String name;
19 |
20 | public Node next;
21 |
22 | public Node() { }
23 | public Node(String name) {
24 | this.name = name;
25 | }
26 | }
27 |
28 | /*
29 | /**********************************************************
30 | /* Test methods
31 | /**********************************************************
32 | */
33 |
34 | private final static String SIMPLE_YAML =
35 | "---\n"
36 | +"&1 name: \"first\"\n"
37 | +"next:\n"
38 | +" &2 name: \"second\"\n"
39 | +" next: *1"
40 | ;
41 |
42 | // For issue [#24]
43 | public void testRoundtripViaTree() throws Exception
44 | {
45 | ObjectMapper mapper = newObjectMapper();
46 | JsonNode root = mapper.readTree(SIMPLE_YAML);
47 | assertNotNull(root);
48 | Node first = mapper.treeToValue(root, Node.class);
49 | assertNotNull(first);
50 | _verify(first);
51 | }
52 |
53 | /*
54 | /**********************************************************
55 | /* Internal helper methods
56 | /**********************************************************
57 | */
58 |
59 | private void _verify(Node first)
60 | {
61 | assertNotNull(first);
62 | assertEquals("first", first.name);
63 | assertNotNull(first.next);
64 | assertEquals("second", first.next.name);
65 | assertNotNull("Should not have null for 'first.next.next'", first.next.next);
66 | assertSame(first, first.next.next);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/failing/SkipEmptyLines15Test.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.failing;
2 |
3 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4 | import com.fasterxml.jackson.dataformat.csv.*;
5 |
6 | public class SkipEmptyLines15Test extends ModuleTestBase
7 | {
8 | @JsonPropertyOrder({ "age", "name", "cute" })
9 | protected static class Entry {
10 | public int age;
11 | public String name;
12 | public boolean cute;
13 | }
14 |
15 | /*
16 | /**********************************************************************
17 | /* Test methods, success
18 | /**********************************************************************
19 | */
20 |
21 | // for [dataformats-text#15]: Allow skipping of empty lines
22 | public void testSkipEmptyLinesFeature() throws Exception
23 | {
24 | final String CSV = "1,\"xyz\"\n\ntrue,\n";
25 |
26 | CsvMapper mapper = mapperForCsv();
27 |
28 | // First, verify default behavior:
29 |
30 | String[][] rows = mapper.readerFor(String[][].class)
31 | .with(CsvParser.Feature.WRAP_AS_ARRAY)
32 | .readValue(CSV);
33 | assertEquals(3, rows.length);
34 | String[] row;
35 |
36 | row = rows[0];
37 | assertEquals(2, row.length);
38 | assertEquals("1",row[0]);
39 | assertEquals("xyz", row[1]);
40 |
41 | row = rows[1];
42 | assertEquals(1, row.length);
43 | assertEquals("", row[0]);
44 |
45 | row = rows[2];
46 | assertEquals(2, row.length);
47 | assertEquals("true", row[0]);
48 | assertEquals("", row[1]);
49 |
50 | // when wrapped as an array, we'll get array of Lists:
51 | rows = mapper.readerFor(String[][].class)
52 | .with(CsvParser.Feature.WRAP_AS_ARRAY)
53 | .with(CsvParser.Feature.SKIP_EMPTY_LINES)
54 | .readValue(CSV);
55 |
56 | assertEquals(2, rows.length);
57 | row = rows[0];
58 | assertEquals(2, row.length);
59 | assertEquals("1",row[0]);
60 | assertEquals("xyz", row[1]);
61 |
62 | row = rows[1];
63 | assertEquals(2, row.length);
64 | assertEquals("true", row[0]);
65 | assertEquals("", row[1]);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/yaml/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | com.fasterxml.jackson.dataformat
6 | jackson-dataformats-text
7 | 3.0.0-SNAPSHOT
8 |
9 | jackson-dataformat-yaml
10 | bundle
11 | Jackson-dataformat-YAML
12 | Support for reading and writing YAML-encoded data via Jackson abstractions.
13 |
14 | https://github.com/FasterXML/jackson-dataformats-text
15 |
16 |
17 | com/fasterxml/jackson/dataformat/yaml
18 | ${project.groupId}.yaml
19 |
20 |
21 |
22 |
23 |
24 | com.fasterxml.jackson.core
25 | jackson-databind
26 |
27 | provided
28 |
29 |
30 |
31 | org.yaml
32 | snakeyaml
33 | 1.19
34 |
35 |
36 |
37 |
38 | com.fasterxml.jackson.core
39 | jackson-annotations
40 | test
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | com.google.code.maven-replacer-plugin
49 | replacer
50 |
51 |
52 | process-packageVersion
53 | generate-sources
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/ParserDupHandlingTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml.deser;
2 |
3 | import java.io.*;
4 |
5 | import com.fasterxml.jackson.core.*;
6 | import com.fasterxml.jackson.databind.ObjectMapper;
7 | import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
8 | import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
9 |
10 | public class ParserDupHandlingTest extends ModuleTestBase
11 | {
12 | private final static String YAML_WITH_DUPS =
13 | "name:\n"
14 | +" first: Bob\n"
15 | +" first: Dup\n";
16 |
17 | public void testDupChecksDisabled() throws Exception
18 | {
19 | YAMLFactory f = new YAMLFactory();
20 | assertFalse(f.isEnabled(JsonParser.Feature.STRICT_DUPLICATE_DETECTION));
21 |
22 | ObjectMapper mapper = new ObjectMapper(f);
23 | _verifyDupsOk(mapper, YAML_WITH_DUPS, false);
24 | _verifyDupsOk(mapper, YAML_WITH_DUPS, true);
25 | }
26 |
27 | public void testDupChecksEnabled() throws Exception
28 | {
29 | YAMLFactory f = YAMLFactory.builder()
30 | .enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION)
31 | .build();
32 | ObjectMapper mapper = new ObjectMapper(f);
33 | _verifyDupsFail(mapper, YAML_WITH_DUPS, false);
34 | _verifyDupsFail(mapper, YAML_WITH_DUPS, true);
35 | }
36 |
37 | private void _verifyDupsOk(ObjectMapper mapper, String doc, boolean useBytes) throws Exception
38 | {
39 | JsonParser p = useBytes ? mapper.createParser(new ByteArrayInputStream(doc.getBytes("UTF-8")))
40 | : mapper.createParser(new StringReader(doc));
41 | _stream(p);
42 | p.close();
43 | }
44 |
45 | private void _verifyDupsFail(ObjectMapper mapper, String doc, boolean useBytes) throws Exception
46 | {
47 | JsonParser p = useBytes ? mapper.createParser(new ByteArrayInputStream(doc.getBytes("UTF-8")))
48 | : mapper.createParser(new StringReader(doc));
49 | try {
50 | _stream(p);
51 | } catch (JsonProcessingException e) {
52 | verifyException(e, "Duplicate field 'first'");
53 | }
54 | p.close();
55 | }
56 |
57 | private void _stream(JsonParser p) throws Exception
58 | {
59 | while (p.nextToken() != null) { }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ser/TestGeneratorNoSchema.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.ser;
2 |
3 | import java.io.*;
4 |
5 | import com.fasterxml.jackson.core.JsonGenerator;
6 | import com.fasterxml.jackson.databind.ObjectWriter;
7 |
8 | import com.fasterxml.jackson.dataformat.csv.CsvMapper;
9 | import com.fasterxml.jackson.dataformat.csv.CsvSchema;
10 | import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;
11 |
12 | public class TestGeneratorNoSchema extends ModuleTestBase
13 | {
14 | private final CsvSchema SCHEMA = CsvSchema.emptySchema()
15 | .withoutHeader()
16 | .withEscapeChar('\\')
17 | .withQuoteChar('"')
18 | .withColumnSeparator(';')
19 | .withLineSeparator("\r\n")
20 | ;
21 |
22 | private final CsvMapper MAPPER = mapperForCsv();
23 |
24 | public void testUntypedAsSequenceStreaming() throws Exception
25 | {
26 | StringWriter sw = new StringWriter();
27 | JsonGenerator gen = MAPPER.createGenerator(sw);
28 | gen.setSchema(SCHEMA);
29 |
30 | assertEquals(0, gen.getOutputBuffered());
31 |
32 | gen.writeStartArray();
33 | gen.writeString("foo");
34 |
35 | // this will be buffered because we output in correct order, so:
36 | assertEquals(3, gen.getOutputBuffered());
37 |
38 | gen.writeNumber(1234567890L);
39 | gen.writeBoolean(true);
40 | gen.writeEndArray();
41 |
42 | gen.writeStartArray();
43 | gen.writeString("bar");
44 | gen.writeNumber(-1250000000000L);
45 | gen.writeBoolean(false);
46 | gen.writeEndArray();
47 |
48 | gen.close();
49 | assertEquals(0, gen.getOutputBuffered());
50 |
51 | String csv = sw.toString();
52 |
53 | assertEquals("foo;1234567890;true\r\n"
54 | +"bar;-1250000000000;false\r\n",
55 | csv);
56 | }
57 |
58 | public void testUntypedAsSequenceDatabind() throws Exception
59 | {
60 | ObjectWriter writer = MAPPER.writer(SCHEMA);
61 |
62 | String csv = writer.writeValueAsString(new Object[] {
63 | new Object[] { "foo", 13, true },
64 | new Object[] { "bar", 28, false }
65 | });
66 | assertEquals("foo;13;true\r\n"
67 | +"bar;28;false\r\n",
68 | csv);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/docs/javadoc/yaml/2.9/com/fasterxml/jackson/dataformat/yaml/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | com.fasterxml.jackson.dataformat.yaml (Jackson-dataformat-YAML 2.9.0 API)
8 |
9 |
10 |
11 |
12 |
13 |
14 |
Classes
15 |
24 |
Enums
25 |
29 |
Exceptions
30 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/docs/javadoc/properties/2.9/com/fasterxml/jackson/dataformat/javaprop/util/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | com.fasterxml.jackson.dataformat.javaprop.util (Jackson-dataformat-Properties 2.9.0 API)
8 |
9 |
10 |
11 |
12 |
13 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/csv/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | com.fasterxml.jackson.dataformat
6 | jackson-dataformats-text
7 | 3.0.0-SNAPSHOT
8 |
9 | jackson-dataformat-csv
10 | Jackson-dataformat-CSV
11 | bundle
12 | Support for reading and writing CSV-encoded data via Jackson
13 | abstractions.
14 |
15 | https://github.com/FasterXML/jackson-dataformats-text
16 |
17 |
18 |
19 | com/fasterxml/jackson/dataformat/csv
20 | ${project.groupId}.csv
21 | com.fasterxml.jackson.dataformat.csv.impl
22 |
23 |
24 |
25 |
26 |
27 | com.fasterxml.jackson.core
28 | jackson-databind
29 |
30 |
34 |
35 | com.fasterxml.jackson.core
36 | jackson-annotations
37 |
38 |
39 |
40 |
41 | com.google.guava
42 | guava
43 | 16.0.1
44 | test
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | com.google.code.maven-replacer-plugin
53 | replacer
54 |
55 |
56 | process-packageVersion
57 | generate-sources
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ser/HeaderWriteTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.ser;
2 |
3 | import java.io.IOException;
4 | import java.io.StringWriter;
5 | import java.util.Arrays;
6 | import java.util.List;
7 |
8 | import com.fasterxml.jackson.databind.SequenceWriter;
9 | import com.fasterxml.jackson.dataformat.csv.*;
10 |
11 | // Tests for verifying that headers are emitted
12 | public class HeaderWriteTest extends ModuleTestBase
13 | {
14 | /*
15 | /**********************************************************************
16 | /* Test methods
17 | /**********************************************************************
18 | */
19 |
20 | private final CsvMapper MAPPER = mapperForCsv();
21 |
22 | public void testNoLines() throws Exception
23 | {
24 | List headers = Arrays.asList("TestHeader1", "TestHeader2");
25 | List> dataSource = Arrays.asList();
26 | String result = runTest(headers, dataSource);
27 |
28 | assertEquals("Headers should have been written even with no other data", "TestHeader1,TestHeader2\n", result);
29 | }
30 |
31 | public void testOneLine() throws Exception
32 | {
33 | List headers = Arrays.asList("TestHeader1", "TestHeader2");
34 | List> dataSource = Arrays.asList(Arrays.asList("TestValue1", "TestValue2"));
35 | String result = runTest(headers, dataSource);
36 |
37 | assertEquals("Headers should have been written before line", "TestHeader1,TestHeader2\nTestValue1,TestValue2\n", result);
38 | }
39 |
40 | private String runTest(List headers, List> dataSource) throws IOException
41 | {
42 | StringWriter writer = new StringWriter();
43 |
44 | CsvSchema.Builder builder = CsvSchema.builder();
45 | for (String nextHeader : headers) {
46 | builder = builder.addColumn(nextHeader);
47 | }
48 |
49 | CsvSchema schema = builder.setUseHeader(true).build();
50 | try (SequenceWriter csvWriter = MAPPER.writerWithDefaultPrettyPrinter()
51 | .with(schema)
52 | .forType(List.class)
53 | .writeValues(writer);) {
54 | for(List nextRow : dataSource) {
55 | csvWriter.write(nextRow);
56 | }
57 | }
58 |
59 | return writer.toString();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/IgnoreUnmappableTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.deser;
2 |
3 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4 |
5 | import com.fasterxml.jackson.databind.JsonMappingException;
6 | import com.fasterxml.jackson.databind.MappingIterator;
7 |
8 | import com.fasterxml.jackson.dataformat.csv.*;
9 |
10 | /**
11 | * Test(s) for [dataformat-csv#95]
12 | */
13 | public class IgnoreUnmappableTest extends ModuleTestBase
14 | {
15 | final CsvMapper MAPPER = mapperForCsv();
16 |
17 | @JsonPropertyOrder({ "first", "second" })
18 | static class StringPair {
19 | public String first, second;
20 | }
21 |
22 | public void testSimpleIgnoral() throws Exception
23 | {
24 | final String INPUT = "a,b,c,foo\nd,e\nf,g,h,i\n";
25 | final CsvSchema schema = MAPPER.schemaFor(StringPair.class);
26 |
27 | // first: throw exception(s) with default settings
28 | MappingIterator it = MAPPER.readerFor(StringPair.class)
29 | .with(schema)
30 | .without(CsvParser.Feature.IGNORE_TRAILING_UNMAPPABLE)
31 | .readValues(INPUT);
32 |
33 | try {
34 | it.nextValue();
35 | fail("Should not have passed");
36 | } catch (JsonMappingException e) {
37 | verifyException(e, "Too many entries");
38 | }
39 |
40 | // yet second one ought to work
41 | StringPair pair = it.nextValue();
42 | assertEquals("d", pair.first);
43 | assertEquals("e", pair.second);
44 |
45 | // and not third, again
46 | try {
47 | it.nextValue();
48 | fail("Should not have passed");
49 | } catch (JsonMappingException e) {
50 | verifyException(e, "Too many entries");
51 | }
52 | it.close();
53 |
54 | // But with settings...
55 | it = MAPPER.readerFor(StringPair.class)
56 | .with(schema)
57 | .with(CsvParser.Feature.IGNORE_TRAILING_UNMAPPABLE)
58 | .readValues(INPUT);
59 |
60 | pair = it.nextValue();
61 | assertEquals("a", pair.first);
62 | assertEquals("b", pair.second);
63 |
64 | pair = it.nextValue();
65 | assertEquals("d", pair.first);
66 | assertEquals("e", pair.second);
67 |
68 | pair = it.nextValue();
69 | assertEquals("f", pair.first);
70 | assertEquals("g", pair.second);
71 |
72 | assertFalse(it.hasNextValue());
73 |
74 | it.close();
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/properties/src/test/java/com/fasterxml/jackson/dataformat/javaprop/DefaultConfigsTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.javaprop;
2 |
3 | import java.io.StringWriter;
4 |
5 | import com.fasterxml.jackson.core.JsonGenerator;
6 | import com.fasterxml.jackson.core.JsonParser;
7 | import com.fasterxml.jackson.core.ObjectReadContext;
8 | import com.fasterxml.jackson.core.ObjectWriteContext;
9 | import com.fasterxml.jackson.core.Version;
10 | import com.fasterxml.jackson.core.Versioned;
11 |
12 | public class DefaultConfigsTest extends ModuleTestBase
13 | {
14 | private final String ARTIFACT_ID = "jackson-dataformat-properties";
15 |
16 | public void testFactoryBaseConfig()
17 | {
18 | JavaPropsFactory f = new JavaPropsFactory();
19 | _verifyVersion(f);
20 | JavaPropsFactory copy = f.copy();
21 | assertNotSame(f, copy);
22 | assertEquals(JavaPropsFactory.FORMAT_NAME_JAVA_PROPERTIES, f.getFormatName());
23 | assertFalse(f.requiresPropertyOrdering());
24 | assertFalse(f.canHandleBinaryNatively());
25 | assertFalse(f.canUseCharArrays());
26 | }
27 |
28 | public void testGeneratorConfig() throws Exception
29 | {
30 | JavaPropsFactory f = new JavaPropsFactory();
31 | JsonGenerator gen = f.createGenerator(ObjectWriteContext.empty(), new StringWriter());
32 | _verifyVersion(gen);
33 | assertTrue(gen.canOmitFields());
34 | assertFalse(gen.canWriteBinaryNatively());
35 | assertTrue(gen.canWriteFormattedNumbers());
36 | assertFalse(gen.canWriteObjectId());
37 | assertFalse(gen.canWriteTypeId());
38 | assertTrue(gen.canUseSchema(JavaPropsSchema.emptySchema()));
39 |
40 | gen.setSchema(JavaPropsSchema.emptySchema());
41 | assertSame(JavaPropsSchema.emptySchema(), gen.getSchema());
42 | gen.close();
43 | }
44 |
45 | public void testParserConfig() throws Exception
46 | {
47 | JavaPropsFactory f = new JavaPropsFactory();
48 | JsonParser p = f.createParser(ObjectReadContext.empty(), "#foo");
49 | _verifyVersion(p);
50 | assertFalse(p.canReadObjectId());
51 | assertFalse(p.canReadTypeId());
52 | assertFalse(p.hasTextCharacters());
53 | assertTrue(p.canUseSchema(JavaPropsSchema.emptySchema()));
54 |
55 | p.setSchema(JavaPropsSchema.emptySchema());
56 | assertSame(JavaPropsSchema.emptySchema(), p.getSchema());
57 | p.close();
58 | }
59 |
60 | private void _verifyVersion(Versioned v) {
61 | Version v2 = v.version();
62 | assertEquals(ARTIFACT_ID, v2.getArtifactId());
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/properties/src/test/java/com/fasterxml/jackson/dataformat/javaprop/SimpleParsingTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.javaprop;
2 |
3 | import java.util.Map;
4 |
5 | import com.fasterxml.jackson.databind.ObjectMapper;
6 |
7 | public class SimpleParsingTest extends ModuleTestBase
8 | {
9 | private final ObjectMapper MAPPER = mapperForProps();
10 |
11 | private final ObjectMapper JSON_MAPPER = new ObjectMapper();
12 |
13 | public void testSimpleNonNested() throws Exception {
14 | _testSimpleNonNested(false);
15 | _testSimpleNonNested(true);
16 | }
17 |
18 | public void testSimpleNested() throws Exception {
19 | _testSimpleNested(false);
20 | _testSimpleNested(true);
21 | }
22 |
23 | public void testSimpleRectangle() throws Exception {
24 | _testSimpleRectangle(false);
25 | _testSimpleRectangle(true);
26 | }
27 |
28 | public void testNonSplittingParsing() throws Exception {
29 | JavaPropsSchema schema = JavaPropsSchema.emptySchema()
30 | .withoutPathSeparator();
31 | Map,?> result = MAPPER.readerFor(Map.class)
32 | .with(schema)
33 | .readValue("a.b.c = 3");
34 | assertEquals("{\"a.b.c\":\"3\"}", JSON_MAPPER.writeValueAsString(result));
35 | }
36 |
37 | private void _testSimpleNonNested(boolean useBytes) throws Exception
38 | {
39 | final String INPUT = "firstName=Bob\n"
40 | +"lastName=Palmer\n"
41 | +"gender=MALE\n"
42 | +"verified=true\n"
43 | +"userImage=AQIDBA==\n";
44 | FiveMinuteUser result = _mapFrom(MAPPER, INPUT, FiveMinuteUser.class, useBytes);
45 | assertEquals(Gender.MALE, result.getGender());
46 | assertEquals(4, result.getUserImage().length);
47 | }
48 |
49 | private void _testSimpleNested(boolean useBytes) throws Exception
50 | {
51 | final String INPUT = "comparison.source.database=test\n"
52 | +"comparison.target.database=test2\n"
53 | ;
54 | Map,?> result = _mapFrom(MAPPER, INPUT, Map.class, useBytes);
55 | assertEquals(1, result.size());
56 | }
57 |
58 | private void _testSimpleRectangle(boolean useBytes) throws Exception
59 | {
60 | final String INPUT = "topLeft.x=1\n"
61 | +"topLeft.y=-2\n"
62 | +"bottomRight.x=5\n"
63 | +"bottomRight.y=10\n";
64 | Rectangle result = _mapFrom(MAPPER, INPUT, Rectangle.class, useBytes);
65 | assertEquals(5, result.bottomRight.x);
66 | assertEquals(10, result.bottomRight.y);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/docs/javadoc/csv/2.9/com/fasterxml/jackson/dataformat/csv/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | com.fasterxml.jackson.dataformat.csv (Jackson-dataformat-CSV 2.9.0 API)
8 |
9 |
10 |
11 |
12 |
13 |
14 |
Classes
15 |
25 |
Enums
26 |
31 |
Exceptions
32 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ser/ArrayWriteTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.ser;
2 |
3 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4 |
5 | import com.fasterxml.jackson.dataformat.csv.*;
6 |
7 | // Tests for verifying that it is possible to write "simple" arrays
8 | // (ones with scalar serializations) as CSV
9 | public class ArrayWriteTest extends ModuleTestBase
10 | {
11 | @JsonPropertyOrder({"id", "values", "extra"})
12 | static class ValueEntry {
13 | public String id, extra;
14 | public int[] values;
15 |
16 | public ValueEntry(String id, String extra, int... v) {
17 | this.id = id;
18 | this.extra = extra;
19 | values = v;
20 | }
21 | }
22 |
23 | @JsonPropertyOrder({"a", "b", "c"})
24 | static class Pojo90 {
25 |
26 | public String[] a = new String[]{"", "foo"};
27 |
28 | public String[] b = new String[]{null, "bar"};
29 |
30 | public String[] c = new String[]{"baz",null};
31 | }
32 |
33 | /*
34 | /**********************************************************************
35 | /* Test methods
36 | /**********************************************************************
37 | */
38 |
39 | private final CsvMapper MAPPER = mapperForCsv();
40 |
41 | public void testSimpleExplicit() throws Exception
42 | {
43 | ValueEntry input = new ValueEntry("foo", "stuff", 1, 2, 3);
44 | String csv = MAPPER.writerWithSchemaFor(ValueEntry.class)
45 | .writeValueAsString(input)
46 | .trim();
47 | assertEquals("foo,1;2;3,stuff", csv);
48 | }
49 |
50 | public void testSeparatorOverride() throws Exception
51 | {
52 | ValueEntry input = new ValueEntry("foo", "stuff", 1, 2, 3);
53 | String csv = MAPPER.writer(CsvSchema.builder()
54 | .addColumn("id")
55 | .addArrayColumn("values", " ")
56 | .addColumn("extra")
57 | .build())
58 | .writeValueAsString(input)
59 | .trim();
60 | // gets quoted due to white space
61 | assertEquals("foo,\"1 2 3\",stuff", csv);
62 | }
63 |
64 | public void testArraysWithNulls() throws Exception
65 | {
66 | Pojo90 value = new Pojo90();
67 | String csvContent = MAPPER.writer(MAPPER.schemaFor(Pojo90.class)
68 | .withHeader())
69 | .writeValueAsString(value);
70 | String[] lines = csvContent.split("\\n");
71 | assertEquals(2, lines.length);
72 | assertEquals("a,b,c", lines[0]);
73 | assertEquals(";foo,;bar,baz;", lines[1]);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/docs/javadoc/yaml/2.9/allclasses-noframe.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | All Classes (Jackson-dataformat-YAML 2.9.0 API)
8 |
9 |
10 |
11 |
12 | All Classes
13 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ser/TestWriterWithMissingValues.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.ser;
2 |
3 | import com.fasterxml.jackson.core.JsonProcessingException;
4 | import com.fasterxml.jackson.databind.ObjectWriter;
5 |
6 | import com.fasterxml.jackson.dataformat.csv.*;
7 |
8 | import com.google.common.collect.ImmutableMap;
9 |
10 | import org.junit.Test;
11 |
12 | import java.lang.String;
13 |
14 | // [Issue#33]
15 | public class TestWriterWithMissingValues extends ModuleTestBase
16 | {
17 | private final CsvSchema SCHEMA = new CsvSchema.Builder()
18 | .addColumn("timestamp", CsvSchema.ColumnType.STRING)
19 | .addColumn("value", CsvSchema.ColumnType.NUMBER)
20 | .addColumn("id", CsvSchema.ColumnType.STRING)
21 | .build();
22 | final ObjectWriter WRITER = new CsvMapper().writer().with(SCHEMA);
23 |
24 | @Test
25 | public void testWrite_NoNulls() throws JsonProcessingException {
26 | final String csv = WRITER.writeValueAsString(
27 | ImmutableMap.of("timestamp", "2014-03-10T23:32:47+00:00",
28 | "value", 42, "id", "hello"));
29 |
30 | assertEquals("\"2014-03-10T23:32:47+00:00\",42,hello\n", csv);
31 | }
32 |
33 | @Test
34 | public void testWrite_NullFirstColumn() throws JsonProcessingException {
35 | final String csv = WRITER.writeValueAsString(
36 | ImmutableMap.of("value", 42, "id", "hello"));
37 | assertEquals(",42,hello\n", csv);
38 | }
39 |
40 | @Test
41 | public void testWrite_NullSecondColumn() throws JsonProcessingException {
42 | final String csv = WRITER.writeValueAsString(
43 | ImmutableMap.of("timestamp", "2014-03-10T23:32:47+00:00",
44 | "id", "hello"));
45 |
46 | assertEquals("\"2014-03-10T23:32:47+00:00\",,hello\n", csv);
47 | }
48 |
49 | @Test
50 | public void testWrite_NullThirdColumn() throws JsonProcessingException
51 | {
52 | CsvMapper mapper = new CsvMapper();
53 | assertFalse(mapper.tokenStreamFactory().isEnabled(CsvGenerator.Feature.OMIT_MISSING_TAIL_COLUMNS));
54 | String csv = mapper.writer(SCHEMA).writeValueAsString(
55 | ImmutableMap.of("timestamp", "2014-03-10T23:32:47+00:00",
56 | "value", 42));
57 |
58 | assertEquals("\"2014-03-10T23:32:47+00:00\",42,\n", csv);
59 | ObjectWriter w = mapper.writer().with(CsvGenerator.Feature.OMIT_MISSING_TAIL_COLUMNS);
60 | csv = w.with(SCHEMA).writeValueAsString(
61 | ImmutableMap.of("timestamp", "2014-03-10T23:32:47+00:00",
62 | "value", 42));
63 | assertEquals("\"2014-03-10T23:32:47+00:00\",42\n", csv);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/TestParserEscapes.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.deser;
2 |
3 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4 | import com.fasterxml.jackson.dataformat.csv.CsvMapper;
5 | import com.fasterxml.jackson.dataformat.csv.CsvSchema;
6 | import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;
7 |
8 | public class TestParserEscapes extends ModuleTestBase
9 | {
10 | @JsonPropertyOrder({"id", "description"})
11 | protected static class Desc {
12 | public String id, desc;
13 | }
14 |
15 | /*
16 | /**********************************************************************
17 | /* Test methods
18 | /**********************************************************************
19 | */
20 |
21 | public void testSimpleEscapesInQuotes() throws Exception
22 | {
23 | CsvMapper mapper = mapperForCsv();
24 | CsvSchema schema = mapper.schemaFor(Desc.class).withColumnSeparator('|').withEscapeChar('\\');
25 | final String id = "abc\\\\def"; // doubled for javac
26 | final String desc = "Desc with\\\nlinefeed";
27 | String input = quote(id)+"|"+quote(desc)+"\n";
28 | Desc result = mapper.reader(schema).forType(Desc.class).readValue(input);
29 | assertEquals("abc\\def", result.id);
30 | assertEquals("Desc with\nlinefeed", result.desc);
31 | }
32 |
33 | /* Specs are unclear as to whether escapes should work in unquoted values;
34 | * but since escape themselves are not officially supported, let's allow
35 | * them for now (can add a config setting if need be)
36 | */
37 | public void testSimpleEscapesInUnquoted() throws Exception
38 | {
39 | CsvMapper mapper = mapperForCsv();
40 | CsvSchema schema = mapper.schemaFor(Desc.class).withColumnSeparator('|').withEscapeChar('\\');
41 | final String id = "abc\\\\def"; // doubled for javac
42 | final String desc = "Desc with\\\nlinefeed";
43 | String input = id+"|"+desc+"\n";
44 | Desc result = mapper.reader(schema).forType(Desc.class).readValue(input);
45 | assertEquals("abc\\def", result.id);
46 | assertEquals("Desc with\nlinefeed", result.desc);
47 | }
48 |
49 | public void testEscapesAtStartInUnquoted() throws Exception
50 | {
51 | CsvMapper mapper = mapperForCsv();
52 | CsvSchema schema = mapper.schemaFor(Desc.class).withColumnSeparator('|').withEscapeChar('\\');
53 | final String id = "\\|abcdef"; // doubled for javac
54 | final String desc = "Desc with\\\nlinefeed";
55 | String input = id+"|"+desc+"\n";
56 | Desc result = mapper.reader(schema).forType(Desc.class).readValue(input);
57 | assertEquals("|abcdef", result.id);
58 | assertEquals("Desc with\nlinefeed", result.desc);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/properties/src/test/java/com/fasterxml/jackson/dataformat/javaprop/ArrayGenerationTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.javaprop;
2 |
3 | import java.util.Properties;
4 |
5 | import com.fasterxml.jackson.dataformat.javaprop.util.Markers;
6 |
7 | public class ArrayGenerationTest extends ModuleTestBase
8 | {
9 | private final JavaPropsMapper MAPPER = mapperForProps();
10 |
11 | public void testPointListSimple() throws Exception
12 | {
13 | Points input = new Points
14 | (new Point(1, 2), new Point(3, 4), new Point(5, 6));
15 | String output = MAPPER.writeValueAsString(input);
16 | assertEquals("p.1.x=1\n"
17 | +"p.1.y=2\n"
18 | +"p.2.x=3\n"
19 | +"p.2.y=4\n"
20 | +"p.3.x=5\n"
21 | +"p.3.y=6\n"
22 | ,output);
23 | Properties props = MAPPER.writeValueAsProperties(input);
24 | assertEquals(6, props.size());
25 | assertEquals("6", props.get("p.3.y"));
26 | assertEquals("1", props.get("p.1.x"));
27 | }
28 |
29 | public void testPointListWithIndex() throws Exception
30 | {
31 | JavaPropsSchema schema = JavaPropsSchema.emptySchema()
32 | .withWriteIndexUsingMarkers(true)
33 | .withFirstArrayOffset(3);
34 | Points input = new Points
35 | (new Point(1, 2), new Point(3, 4), new Point(5, 6));
36 | String output = MAPPER.writer(schema)
37 | .writeValueAsString(input);
38 | assertEquals("p[3].x=1\n"
39 | +"p[3].y=2\n"
40 | +"p[4].x=3\n"
41 | +"p[4].y=4\n"
42 | +"p[5].x=5\n"
43 | +"p[5].y=6\n"
44 | ,output);
45 | Properties props = MAPPER.writeValueAsProperties(input, schema);
46 | assertEquals(6, props.size());
47 | assertEquals("2", props.get("p[3].y"));
48 | assertEquals("3", props.get("p[4].x"));
49 | }
50 |
51 | public void testPointListWithCustomMarkers() throws Exception
52 | {
53 | JavaPropsSchema schema = JavaPropsSchema.emptySchema()
54 | .withWriteIndexUsingMarkers(true)
55 | .withIndexMarker(Markers.create("<<", ">>"))
56 | ;
57 | Points input = new Points(new Point(1, 2), new Point(3, 4));
58 | String output = MAPPER.writer(schema)
59 | .writeValueAsString(input);
60 | assertEquals("p<<1>>.x=1\n"
61 | +"p<<1>>.y=2\n"
62 | +"p<<2>>.x=3\n"
63 | +"p<<2>>.y=4\n"
64 | ,output);
65 | Properties props = MAPPER.writeValueAsProperties(input, schema);
66 | assertEquals(4, props.size());
67 | assertEquals("1", props.get("p<<1>>.x"));
68 | assertEquals("4", props.get("p<<2>>.y"));
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLFactoryBuilder.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml;
2 |
3 | import com.fasterxml.jackson.core.base.DecorableTSFactory.DecorableTSFBuilder;
4 |
5 | /**
6 | * {@link com.fasterxml.jackson.core.TokenStreamFactory.TSFBuilder}
7 | * implementation for constructing {@link YAMLFactory}
8 | * instances.
9 | *
10 | * @since 3.0
11 | */
12 | public class YAMLFactoryBuilder extends DecorableTSFBuilder
13 | {
14 | /*
15 | /**********************************************************
16 | /* Configuration
17 | /**********************************************************
18 | */
19 |
20 | // protected int _formatParserFeatures;
21 |
22 | /**
23 | * Set of {@link YAMLGenerator.Feature}s enabled, as bitmask.
24 | */
25 | protected int _formatGeneratorFeatures;
26 |
27 | /*
28 | /**********************************************************
29 | /* Life cycle
30 | /**********************************************************
31 | */
32 |
33 | protected YAMLFactoryBuilder() {
34 | _formatGeneratorFeatures = YAMLFactory.DEFAULT_YAML_GENERATOR_FEATURE_FLAGS;
35 | }
36 |
37 | public YAMLFactoryBuilder(YAMLFactory base) {
38 | super(base);
39 | _formatGeneratorFeatures = base._formatGeneratorFeatures;
40 | }
41 |
42 | // // // Parser features NOT YET defined
43 |
44 | // // // Generator features
45 |
46 | public YAMLFactoryBuilder enable(YAMLGenerator.Feature f) {
47 | _formatGeneratorFeatures |= f.getMask();
48 | return _this();
49 | }
50 |
51 | public YAMLFactoryBuilder enable(YAMLGenerator.Feature first, YAMLGenerator.Feature... other) {
52 | _formatGeneratorFeatures |= first.getMask();
53 | for (YAMLGenerator.Feature f : other) {
54 | _formatGeneratorFeatures |= f.getMask();
55 | }
56 | return _this();
57 | }
58 |
59 | public YAMLFactoryBuilder disable(YAMLGenerator.Feature f) {
60 | _formatGeneratorFeatures &= ~f.getMask();
61 | return _this();
62 | }
63 |
64 | public YAMLFactoryBuilder disable(YAMLGenerator.Feature first, YAMLGenerator.Feature... other) {
65 | _formatGeneratorFeatures &= ~first.getMask();
66 | for (YAMLGenerator.Feature f : other) {
67 | _formatGeneratorFeatures &= ~f.getMask();
68 | }
69 | return _this();
70 | }
71 |
72 | public YAMLFactoryBuilder configure(YAMLGenerator.Feature f, boolean state) {
73 | return state ? enable(f) : disable(f);
74 | }
75 |
76 | // // // Accessors
77 |
78 | // public int formatParserFeaturesMask() { return _formatParserFeatures; }
79 | public int formatGeneratorFeaturesMask() { return _formatGeneratorFeatures; }
80 |
81 | @Override
82 | public YAMLFactory build() {
83 | return new YAMLFactory(this);
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/docs/javadoc/yaml/2.9/allclasses-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | All Classes (Jackson-dataformat-YAML 2.9.0 API)
8 |
9 |
10 |
11 |
12 | All Classes
13 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/PolymorphicIdTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml;
2 |
3 | import org.junit.Test;
4 |
5 | import com.fasterxml.jackson.annotation.*;
6 | import com.fasterxml.jackson.databind.*;
7 | import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
8 |
9 | public class PolymorphicIdTest extends ModuleTestBase
10 | {
11 | static class Wrapper {
12 | public Nested nested;
13 | }
14 |
15 | @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
16 | @JsonSubTypes({ @JsonSubTypes.Type(value = NestedImpl.class) })
17 | static interface Nested { }
18 |
19 | @JsonTypeName("single")
20 | static class NestedImpl implements Nested {
21 | public String value;
22 | }
23 |
24 | @Test
25 | public void testPolymorphicType() throws Exception
26 | {
27 | // first, with value
28 | String YAML = "nested:\n"
29 | +" type: single\n"
30 | +" value: whatever";
31 | ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
32 | Wrapper top = mapper.readValue(YAML, Wrapper.class);
33 | assertNotNull(top);
34 | assertEquals(NestedImpl.class, top.nested.getClass());
35 | assertEquals("whatever", ((NestedImpl) top.nested).value);
36 |
37 | // then without value
38 | YAML = "nested:\n"
39 | +" type: single";
40 | top = mapper.readValue(YAML, Wrapper.class);
41 | assertNotNull(top);
42 | assertEquals(NestedImpl.class, top.nested.getClass());
43 | assertNull("whatever", ((NestedImpl) top.nested).value);
44 | }
45 |
46 | @Test
47 | public void testNativePolymorphicType() throws Exception {
48 | String YAML = "nested: !single\n"
49 | +" value: foobar\n"
50 | ;
51 | ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
52 | Wrapper top = mapper.readValue(YAML, Wrapper.class);
53 | assertNotNull(top);
54 | assertNotNull(top.nested);
55 | assertEquals(NestedImpl.class, top.nested.getClass());
56 | assertEquals("foobar", ((NestedImpl) top.nested).value);
57 |
58 | YAML = "nested: !single { }\n";
59 | top = mapper.readValue(YAML, Wrapper.class);
60 | assertNotNull(top);
61 | assertNotNull(top.nested);
62 | assertEquals(NestedImpl.class, top.nested.getClass());
63 | // no value specified, empty
64 |
65 | // And third possibility; trickier, since YAML contains empty String,
66 | // and not Object; so we need to allow coercion
67 | ObjectReader r = mapper.readerFor(Wrapper.class)
68 | .with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
69 | YAML = "nested: !single\n";
70 | top = r.readValue(YAML);
71 | assertNotNull(top);
72 |
73 | // and as a result, get null
74 | assertNull(top.nested);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ser/GeneratorIgnoreUnknown51Test.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.ser;
2 |
3 | import java.io.StringWriter;
4 | import java.util.*;
5 |
6 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
7 |
8 | import com.fasterxml.jackson.core.JsonGenerator;
9 |
10 | import com.fasterxml.jackson.dataformat.csv.CsvMapper;
11 | import com.fasterxml.jackson.dataformat.csv.CsvMappingException;
12 | import com.fasterxml.jackson.dataformat.csv.CsvSchema;
13 | import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;
14 |
15 | public class GeneratorIgnoreUnknown51Test extends ModuleTestBase
16 | {
17 | // [dataformats-text#51]
18 | @JsonPropertyOrder({ "address", "people", "phoneNumber" })
19 | protected static class MyClass
20 | {
21 | public String address;
22 | public Set people;
23 | public String phoneNumber;
24 |
25 | public MyClass() { }
26 | }
27 |
28 | @JsonPropertyOrder({ "name", "surname" })
29 | protected static class Person
30 | {
31 | public String name, surname;
32 |
33 | protected Person() { }
34 |
35 | public Person(String name, String surname)
36 | {
37 | this.name = name;
38 | this.surname = surname;
39 | }
40 |
41 |
42 | // 07-Nov-2017, tatu: This would be a work-around:
43 | //@JsonValue
44 | public String asString() {
45 | return ""+name+" "+surname;
46 | }
47 | }
48 |
49 | /*
50 | /**********************************************************
51 | /* Test methods
52 | /**********************************************************
53 | */
54 |
55 | // for [dataformats-text#51]
56 | public void testIgnoreEmbeddedObject() throws Exception
57 | {
58 | CsvMapper mapper = CsvMapper.builder()
59 | .enable(JsonGenerator.Feature.IGNORE_UNKNOWN)
60 | .build();
61 | CsvSchema schema = CsvSchema.builder()
62 | .addColumn("address")
63 | .addColumn("people") // here I'm skipping phoneNumber so I need to use IGNORE_UNKNOWN feature
64 | .build()
65 | .withHeader();
66 |
67 | Person firstPerson = new Person("Barbie", "Benton");
68 | Person secondPerson = new Person("Veltto", "Virtanen");
69 | Set people = new LinkedHashSet<>();
70 | people.add(firstPerson);
71 | people.add(secondPerson);
72 | MyClass myClass = new MyClass();
73 | myClass.people = people;
74 | myClass.address = "AAA";
75 | myClass.phoneNumber = "123";
76 |
77 | StringWriter sw = new StringWriter();
78 | try {
79 | mapper.writer(schema).writeValue(sw, myClass);
80 | fail("Should not pass");
81 | } catch (CsvMappingException e) {
82 | verifyException(e, "CSV generator does not support");
83 | verifyException(e, "nested Objects");
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ser/MultipleWritesTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.ser;
2 |
3 | import java.io.*;
4 | import java.util.*;
5 |
6 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
7 | import com.fasterxml.jackson.core.JsonGenerator;
8 | import com.fasterxml.jackson.databind.*;
9 | import com.fasterxml.jackson.dataformat.csv.CsvMapper;
10 | import com.fasterxml.jackson.dataformat.csv.CsvSchema;
11 | import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;
12 |
13 | public class MultipleWritesTest extends ModuleTestBase
14 | {
15 | @JsonPropertyOrder({ "a", "b", "c" })
16 | public static class Pojo {
17 | public int a, b, c;
18 |
19 | public Pojo(int a, int b, int c) {
20 | this.a = a;
21 | this.b = b;
22 | this.c = c;
23 | }
24 | }
25 |
26 | private final CsvMapper MAPPER = mapperForCsv();
27 |
28 | /**
29 | * To reproduce [dataformat-csv#71]: Although ideally one uses
30 | * `ObjectWriter.writeValues()` for sequences, we should not
31 | * write headers more than once regardless, as long as target
32 | * is CsvGenerator which tracks state.
33 | */
34 | public void testMultipleListWrites() throws Exception
35 | {
36 | StringWriter sw = new StringWriter();
37 |
38 | CsvSchema.Builder builder = CsvSchema.builder();
39 | builder.addColumn("col1");
40 | builder.addColumn("col2");
41 |
42 | CsvSchema csvSchema = builder.build().withHeader();
43 |
44 | JsonGenerator gen = MAPPER.createGenerator(sw);
45 | // IMPORTANT! If passing generator, must directly configure it:
46 | gen.setSchema(csvSchema);
47 |
48 | ObjectWriter csvWriter = MAPPER.writer();
49 |
50 | List line1 = new ArrayList();
51 | line1.add("line1-val1");
52 | line1.add("line1-val2");
53 |
54 | csvWriter.writeValue(gen, line1);
55 |
56 | List line2 = new ArrayList();
57 | line2.add("line2-val1");
58 | line2.add("line2-val2");
59 |
60 | csvWriter.writeValue(gen, line2);
61 |
62 | gen.close();
63 |
64 | String csv = sw.toString().trim();
65 | // may get different linefeed on different OSes?
66 | csv = csv.replaceAll("[\\r\\n]", "/");
67 | assertEquals("col1,col2/line1-val1,line1-val2/line2-val1,line2-val2", csv);
68 | }
69 |
70 | public void testWriteValuesWithPOJOs() throws Exception
71 | {
72 | CsvSchema schema = MAPPER.schemaFor(Pojo.class).withUseHeader(true);
73 | ObjectWriter writer = MAPPER.writer(schema);
74 | StringWriter sw = new StringWriter();
75 | SequenceWriter seqw = writer.writeValues(sw);
76 | seqw.write(new Pojo(1, 2, 3));
77 | seqw.write(new Pojo(0, 15, 9));
78 | seqw.write(new Pojo(7, 8, 9));
79 | seqw.flush();
80 | assertEquals("a,b,c\n1,2,3\n0,15,9\n7,8,9\n",
81 | sw.toString());
82 | seqw.close();
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/release-notes/VERSION-2.x:
--------------------------------------------------------------------------------
1 | Project: jackson-datatypes-text
2 | Modules:
3 | jackson-dataformat-csv
4 | jackson-dataformat-properties
5 | jackson-dataformat-yaml
6 |
7 | ------------------------------------------------------------------------
8 | === Releases ===
9 | ------------------------------------------------------------------------
10 |
11 | 2.9.6 (12-Jun-2018)
12 |
13 | #84 (yaml): Add option to allow use of platform-linefeed
14 | (`YAMLGenerator.Feature.USE_PLATFORM_LINE_BREAKS`)
15 | (contributed by Thomas H)
16 |
17 | 2.9.5 (26-Mar-2018)
18 |
19 | #74 (properties): `JavaPropsMapper` issue deserializing multiple byte array properties
20 | (reported by Fabrice D)
21 |
22 | 2.9.4 (24-Jan-2018)
23 |
24 | #62 (yaml): SnakeYAML base64Coder is not OSGI exported
25 | (reported by mbechler@github)
26 | #65 (yaml): `YAMLParser` incorrectly handles numbers with underscores in them
27 | (reported by Mike K)
28 |
29 | 2.9.3 (09-Dec-2017)
30 |
31 | #39 (yaml): Binary data not recognized by YAML parser
32 | (repoted by tmoschou@github)
33 | #42 (csv): Add support for escaping double quotes with the configured escape character
34 | (contributed by frankgrimes97@github)
35 | #51 (csv): Set of custom objects with `IGNORE_UNKNOWN` brokes silently csv
36 | (reported by Simone L)
37 | #53: (yaml) Binary values written without type tag
38 | (reported by arulrajnet@github)
39 |
40 | 2.9.2 (14-Oct-2017)
41 |
42 | No changes since 2.9.1
43 |
44 | 2.9.1 (07-Sep-2017)
45 |
46 | #34: (yaml) Problem with `YAMLGenerator.Feature.INDENT_ARRAYS`, nested Objects
47 | (yaml): Upgrade `SnakeYAML` dep 1.17 -> 1.18
48 |
49 | 2.9.0 (30-Jul-2017)
50 |
51 | CSV:
52 | (Note: issue numbers point to old, separate repos of `jackson-dataformat-csv`)
53 |
54 | #127: Add `CsvGenerator.Feature.ALWAYS_QUOTE_EMPTY_STRINGS` to allow forced
55 | quoting of empty Strings.
56 | (contributed by georgewfraser@github)
57 | #130: Add fluent addColumns operation to CsvSchema.Builder
58 | (contributed by Peter A)
59 | #137: Inject "missing" trailing columns as `null`s
60 | (`JsonParser.Feature.INSERT_NULLS_FOR_MISSING_COLUMNS`)
61 | #139: Add `CsvParser.Feature.ALLOW_TRAILING_COMMA` to allow enforcing strict handling
62 | (contributed by Nick B)
63 | #140: Fail for missing column values (`JsonParser.Feature.FAIL_ON_MISSING_COLUMNS`)
64 | (suggested by jwilmoth@github)
65 | #142: Add methods for appending columns of a `CsvSchema` into another
66 | (suggested by Austin S)
67 | - Add new exception type `CsvMappingException` to indicate CSV-mapping issues (and
68 | give access to effective Schema)
69 |
70 | Properties:
71 |
72 | #1: Add convenience method(s) for reading System properties
73 | #3: Write into `Properties` instance (factory, mapper) using
74 | `JavaPropsMapper.writeValue()` with `Properties` and
75 | `JavaPropsMapper.writeValueAsProperties()`
76 | #4: Allow binding from `Properties` instance
77 |
78 | YAML:
79 | (Note: issue numbers point to old, separate repos of `jackson-dataformat-yaml`)
80 |
81 | #67: Add `YAMLGenerator.Feature.INDENT_ARRAYS`
82 | #76: Add `YAMLGenerator.Feature.LITERAL_BLOCK_STYLE` for String output
83 | (contributed by Roland H)
84 |
--------------------------------------------------------------------------------
/docs/javadoc/csv/2.9/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Jackson-dataformat-CSV 2.9.0 API
8 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | JavaScript is disabled on your browser.
70 |
71 | Frame Alert
72 | This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version .
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/docs/javadoc/yaml/2.9/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Jackson-dataformat-YAML 2.9.0 API
8 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | JavaScript is disabled on your browser.
70 |
71 | Frame Alert
72 | This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version .
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/docs/javadoc/properties/2.9/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Jackson-dataformat-Properties 2.9.0 API
8 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | JavaScript is disabled on your browser.
70 |
71 | Frame Alert
72 | This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version .
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/csv/release-notes/CREDITS:
--------------------------------------------------------------------------------
1 | Project: jackson-dataformat-csv
2 |
3 | Here are people who have contributed to development of this project:
4 | (version numbers in parenthesis indicate release in which the problem was fixed)
5 |
6 | Tatu Saloranta, tatu.saloranta@iki.fi: author
7 |
8 | Lior Lipshitz (from zazma.com)
9 |
10 | * Reported #14: Incorrect quoting of double-quotes for long String values that
11 | cross buffer boundary
12 | (2.1.5 / 2.2.0)
13 |
14 | Paul Magrath (Magrath@github)
15 |
16 | * Reported #33: CSV is written without column separators if first column is null
17 | (2.3.3)
18 | * Reported #38: Extra column delimiter added when column is escaped and follows empty column
19 | (2.3.4)
20 |
21 | Jason Dunkelberger (dirkraft@github)
22 |
23 | * Suggested #32: Allow disabling of quoteChar
24 | (2.4.0)
25 |
26 | Wei Li (wli600@github)
27 |
28 | * Contributed fix for 54: Encounter ArrayIndexOutOfBoundsException in the corner case delimiter
29 | or end-of-line happened to be the leading character of a segment buffer
30 | (2.4.4)
31 |
32 | Luke Nezda (nezda@github)
33 |
34 | * Suggested #56: Support comments (either via `CsvSchema`, or using std
35 | `JsonParser.Feature.ALLOW_YAML_COMMENTS.
36 | (requested by nezda@github)
37 | (2.5.0)
38 |
39 | David Navas (davidnavas@github)
40 |
41 | * Contributed #75: Support escapes at beginning of the file
42 | (2.5.3)
43 |
44 | sothmann@github)
45 |
46 | * Reported #83: Serializing List with null values leads to corrupt CSV
47 | (2.6.0)
48 |
49 | Jonathan Cheseaux (cheseaux@github)
50 |
51 | * Reported #90: Unexpected output with arrays starting with a null/empty element
52 | (2.6.4)
53 |
54 | Oliver Röss (cloudyday@github)
55 |
56 | * Reported #98: Escape char is not being escaped during serialization
57 | (2.6.4)
58 |
59 | Justo Ruiz Ferrer (jrferrer@github)
60 |
61 | * Contributed #89: Allow choice of using header-line declaration to reorder columns
62 | of explicit schema, with `CsvSchema.setReorderColumns`
63 | (2.7.0)
64 |
65 | Rob Baily (rob-baily@github)
66 |
67 | * Contributed fix for #93: CSV mapper does not support Views or filtering correctly
68 | for serialization
69 | (2.6.5)
70 |
71 | dharaburda@github)
72 |
73 | * Contributed fix for #100: trim spaces: don't trim/strip separator character
74 | (2.6.5)
75 |
76 | Nick Babcock (nickbabcock@github)
77 |
78 | * Contributed #97: Verify CSV headers are in the order as expected (added `strictHeaders`
79 | property in `CsvSchema`)
80 | (2.7.0)
81 | * Constributed #139: Add `CsvParser.Feature.ALLOW_TRAILING_COMMA` to allow enforcing
82 | strict handling
83 | (2.9.0)
84 |
85 | Brian Moriarty (morbrian@github)
86 |
87 | * Contributed #106: Null fields are always ignored when serializing list of objects
88 | (2.7.0)
89 |
90 | Peter Ansell (ansell@github)
91 |
92 | * Contributed fix for #128: Write out headers even if no data rows written
93 | (2.7.7)
94 |
95 | George Fraser (georgewfraser@github)
96 |
97 | * Contributed #127: Add `CsvGenerator.Feature.ALWAYS_QUOTE_EMPTY_STRINGS` to allow forced
98 | quoting of empty Strings.
99 | (2.9.0)
100 |
101 | Austin Sharp (sharpau@github)
102 |
103 | * Suggested #142: Add methods for appending columns of a `CsvSchema` into another
104 | (2.9.0)
105 |
--------------------------------------------------------------------------------
/release-notes/CREDITS-old-csv.txt:
--------------------------------------------------------------------------------
1 | Project: jackson-dataformat-csv
2 |
3 | Here are people who have contributed to development of this project:
4 | (version numbers in parenthesis indicate release in which the problem was fixed)
5 |
6 | Tatu Saloranta, tatu.saloranta@iki.fi: author
7 |
8 | Lior Lipshitz (from zazma.com)
9 |
10 | * Reported #14: Incorrect quoting of double-quotes for long String values that
11 | cross buffer boundary
12 | (2.1.5 / 2.2.0)
13 |
14 | Paul Magrath (Magrath@github)
15 |
16 | * Reported #33: CSV is written without column separators if first column is null
17 | (2.3.3)
18 | * Reported #38: Extra column delimiter added when column is escaped and follows empty column
19 | (2.3.4)
20 |
21 | Jason Dunkelberger (dirkraft@github)
22 |
23 | * Suggested #32: Allow disabling of quoteChar
24 | (2.4.0)
25 |
26 | Wei Li (wli600@github)
27 |
28 | * Contributed fix for 54: Encounter ArrayIndexOutOfBoundsException in the corner case delimiter
29 | or end-of-line happened to be the leading character of a segment buffer
30 | (2.4.4)
31 |
32 | Luke Nezda (nezda@github)
33 |
34 | * Suggested #56: Support comments (either via `CsvSchema`, or using std
35 | `JsonParser.Feature.ALLOW_YAML_COMMENTS.
36 | (requested by nezda@github)
37 | (2.5.0)
38 |
39 | David Navas (davidnavas@github)
40 |
41 | * Contributed #75: Support escapes at beginning of the file
42 | (2.5.3)
43 |
44 | sothmann@github)
45 |
46 | * Reported #83: Serializing List with null values leads to corrupt CSV
47 | (2.6.0)
48 |
49 | Jonathan Cheseaux (cheseaux@github)
50 |
51 | * Reported #90: Unexpected output with arrays starting with a null/empty element
52 | (2.6.4)
53 |
54 | Oliver Röss (cloudyday@github)
55 |
56 | * Reported #98: Escape char is not being escaped during serialization
57 | (2.6.4)
58 |
59 | Justo Ruiz Ferrer (jrferrer@github)
60 |
61 | * Contributed #89: Allow choice of using header-line declaration to reorder columns
62 | of explicit schema, with `CsvSchema.setReorderColumns`
63 | (2.7.0)
64 |
65 | Rob Baily (rob-baily@github)
66 |
67 | * Contributed fix for #93: CSV mapper does not support Views or filtering correctly
68 | for serialization
69 | (2.6.5)
70 |
71 | dharaburda@github)
72 |
73 | * Contributed fix for #100: trim spaces: don't trim/strip separator character
74 | (2.6.5)
75 |
76 | Nick Babcock (nickbabcock@github)
77 |
78 | * Contributed #97: Verify CSV headers are in the order as expected (added `strictHeaders`
79 | property in `CsvSchema`)
80 | (2.7.0)
81 | * Constributed #139: Add `CsvParser.Feature.ALLOW_TRAILING_COMMA` to allow enforcing
82 | strict handling
83 | (2.9.0)
84 |
85 | Brian Moriarty (morbrian@github)
86 |
87 | * Contributed #106: Null fields are always ignored when serializing list of objects
88 | (2.7.0)
89 |
90 | Peter Ansell (ansell@github)
91 |
92 | * Contributed fix for #128: Write out headers even if no data rows written
93 | (2.7.7)
94 |
95 | George Fraser (georgewfraser@github)
96 |
97 | * Contributed #127: Add `CsvGenerator.Feature.ALWAYS_QUOTE_EMPTY_STRINGS` to allow forced
98 | quoting of empty Strings.
99 | (2.9.0)
100 |
101 | Austin Sharp (sharpau@github)
102 |
103 | * Suggested #142: Add methods for appending columns of a `CsvSchema` into another
104 | (2.9.0)
105 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.fasterxml.jackson
5 | jackson-base
6 | 3.0.0-SNAPSHOT
7 |
8 | com.fasterxml.jackson.dataformat
9 | jackson-dataformats-text
10 | Jackson dataformats: Text
11 | 3.0.0-SNAPSHOT
12 | pom
13 | Parent pom for Jackson text-based dataformats (as opposed to binary).
14 |
15 |
16 |
17 | csv
18 | properties
19 | yaml
20 |
21 |
22 | https://github.com/FasterXML/jackson-dataformats-text
23 |
24 | scm:git:git@github.com:FasterXML/jackson-dataformats-text.git
25 | scm:git:git@github.com:FasterXML/jackson-dataformats-text.git
26 | http://github.com/FasterXML/jackson-dataformats-text
27 | HEAD
28 |
29 |
30 | https://github.com/FasterXML/jackson-dataformats-text/issues
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | com.fasterxml.jackson.core
40 | jackson-core
41 |
42 |
43 |
44 | junit
45 | junit
46 | test
47 |
48 |
49 |
50 |
52 |
53 |
54 | sonatype-nexus-snapshots
55 | Sonatype Nexus Snapshots
56 | https://oss.sonatype.org/content/repositories/snapshots
57 | false
58 | true
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | com.google.code.maven-replacer-plugin
68 | replacer
69 |
70 |
71 | process-packageVersion
72 | generate-sources
73 |
74 |
75 |
76 |
77 |
78 | org.apache.maven.plugins
79 | maven-surefire-plugin
80 |
81 |
82 | com/fasterxml/jackson/**/failing/*.java
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/DatabindWriteTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml.ser;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.File;
5 | import java.io.FileInputStream;
6 | import java.io.InputStreamReader;
7 | import java.util.HashMap;
8 | import java.util.Iterator;
9 | import java.util.Map;
10 | import java.util.TreeSet;
11 |
12 | import com.fasterxml.jackson.databind.ObjectMapper;
13 | import com.fasterxml.jackson.databind.node.ObjectNode;
14 | import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
15 |
16 | public class DatabindWriteTest extends ModuleTestBase
17 | {
18 | public void testBasicPOJO() throws Exception
19 | {
20 | ObjectMapper mapper = newObjectMapper();
21 | FiveMinuteUser user = new FiveMinuteUser("Bob", "Dabolito", false,
22 | FiveMinuteUser.Gender.MALE, new byte[] { 1, 3, 13, 79 });
23 | String yaml = mapper.writeValueAsString(user).trim();
24 | String[] parts = yaml.split("\n");
25 | // unify ordering, need to use TreeSets to get alphabetic ordering
26 | TreeSet exp = new TreeSet();
27 | for (String part : parts) {
28 | exp.add(part.trim());
29 | }
30 | Iterator it = exp.iterator();
31 | assertEquals("---", it.next());
32 | assertEquals("AQMNTw==", it.next());
33 | assertEquals("firstName: \"Bob\"", it.next());
34 | assertEquals("gender: \"MALE\"", it.next());
35 | assertEquals("lastName: \"Dabolito\"", it.next());
36 | // 15-Dec-2017, tatu: different linefeed modes, see f.ex:
37 | // https://stackoverflow.com/questions/3790454/in-yaml-how-do-i-break-a-string-over-multiple-lines
38 | String line = it.next();
39 | String expLine = "userImage: !!binary |";
40 | if (line.endsWith("|-")) {
41 | expLine += "-";
42 | }
43 | assertEquals(expLine, line);
44 | assertEquals("verified: false", it.next());
45 | assertFalse(it.hasNext());
46 | }
47 |
48 | public void testWithFile() throws Exception
49 | {
50 | File f = File.createTempFile("test", ".yml");
51 | f.deleteOnExit();
52 | ObjectMapper mapper = newObjectMapper();
53 | Map map = new HashMap();
54 | map.put("a", 3);
55 | mapper.writeValue(f, map);
56 | assertTrue(f.canRead());
57 | BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(
58 | f), "UTF-8"));
59 | String doc = br.readLine();
60 | String str = br.readLine();
61 | if (str != null) {
62 | doc += "\n" + str;
63 | }
64 | doc = trimDocMarker(doc);
65 | assertEquals("a: 3", doc);
66 | br.close();
67 | f.delete();
68 | }
69 |
70 | public void testWithFile2() throws Exception
71 | {
72 | File f = File.createTempFile("test", ".yml");
73 | f.deleteOnExit();
74 | ObjectMapper mapper = newObjectMapper();
75 | ObjectNode root = mapper.createObjectNode();
76 | root.put("name", "Foobar");
77 | mapper.writeValue(f, root);
78 |
79 | // and get it back
80 | Map,?> result = mapper.readValue(f, Map.class);
81 | assertEquals(1, result.size());
82 | assertEquals("Foobar", result.get("name"));
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/TestParserWorkarounds.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.deser;
2 |
3 | import java.util.Map;
4 |
5 | import com.fasterxml.jackson.core.*;
6 |
7 | import com.fasterxml.jackson.databind.*;
8 |
9 | import com.fasterxml.jackson.dataformat.csv.CsvSchema;
10 | import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;
11 |
12 | /**
13 | * Tests that verify that various minor workarounds
14 | * work as expected.
15 | */
16 | public class TestParserWorkarounds extends ModuleTestBase
17 | {
18 | /**
19 | * Test for [#1]; in case we get an extra empty element,
20 | * we can just ignore it.
21 | */
22 | public void testIgnoringOptionalTrailing() throws Exception
23 | {
24 | ObjectMapper mapper = mapperForCsv();
25 | CsvSchema schema = CsvSchema.builder()
26 | .addColumn("first")
27 | .addColumn("second")
28 | .build();
29 |
30 | MappingIterator> it = mapper.reader(schema).forType(Map.class).readValues(
31 | "a,b\nc,d,\ne,f, \nfoo,bar,x\n");
32 | assertTrue(it.hasNext());
33 |
34 | // first should have no problems anyway:
35 | Map,?> result = it.nextValue();
36 | assertEquals(2, result.size());
37 | assertEquals("a", result.get("first"));
38 | assertEquals("b", result.get("second"));
39 |
40 | // but second and third should skip empty trailing values
41 | assertTrue(it.hasNextValue());
42 | result = it.nextValue();
43 | assertEquals(2, result.size());
44 | assertEquals("c", result.get("first"));
45 | assertEquals("d", result.get("second"));
46 |
47 | assertTrue(it.hasNextValue());
48 | result = it.nextValue();
49 | assertEquals(2, result.size());
50 | assertEquals("e", result.get("first"));
51 | assertEquals("f", result.get("second"));
52 |
53 | // but then the fourth row should give an error; last entry not empty
54 | assertTrue(it.hasNextValue());
55 | try {
56 | result = it.nextValue();
57 | fail("Expected an error");
58 | } catch (JsonMappingException e) {
59 | verifyException(e, "Too many entries");
60 | }
61 | it.close();
62 | }
63 |
64 | // also ensure [databind-csv#1] also works appropriately for failing case
65 | public void testOptionalTrailFailing() throws Exception
66 | {
67 | ObjectMapper mapper = mapperForCsv();
68 | CsvSchema schema = CsvSchema.builder()
69 | .addColumn("first")
70 | .addColumn("second")
71 | .build();
72 |
73 | MappingIterator> it = mapper.reader(schema).forType(Map.class).readValues(
74 | "a,b,\nc,d,,,\n");
75 | assertTrue(it.hasNext());
76 |
77 | // first should have no problems with extra entry
78 | Map,?> result = it.nextValue();
79 | assertEquals(2, result.size());
80 | assertEquals("a", result.get("first"));
81 | assertEquals("b", result.get("second"));
82 |
83 | // but second is problematic
84 | try {
85 | result = it.nextValue();
86 | fail("Should have failed");
87 | } catch (JsonProcessingException e) {
88 | verifyException(e, "Too many entries: expected at most 2");
89 | }
90 | it.close();
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/docs/javadoc/csv/2.9/com/fasterxml/jackson/dataformat/csv/impl/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | com.fasterxml.jackson.dataformat.csv.impl (Jackson-dataformat-CSV 2.9.0 API)
8 |
9 |
10 |
11 |
12 |
13 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/UnwrappingWithCSVTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.deser;
2 |
3 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4 | import com.fasterxml.jackson.annotation.JsonUnwrapped;
5 | import com.fasterxml.jackson.databind.ObjectMapper;
6 | import com.fasterxml.jackson.dataformat.csv.CsvMapper;
7 | import com.fasterxml.jackson.dataformat.csv.CsvSchema;
8 | import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;
9 |
10 | // for #12
11 | public class UnwrappingWithCSVTest extends ModuleTestBase
12 | {
13 | @JsonPropertyOrder({"x", "y"})
14 | final static class Location {
15 | public int x;
16 | public int y;
17 |
18 | public Location() { }
19 | public Location(int x, int y) {
20 | this.x = x;
21 | this.y = y;
22 | }
23 | }
24 |
25 | // IMPORTANT: ordering DOES matter here
26 | @JsonPropertyOrder({ "name", "location" })
27 | static class Unwrapping {
28 | public String name;
29 | @JsonUnwrapped(prefix="loc.")
30 | public Location location;
31 |
32 | public Unwrapping() { }
33 | public Unwrapping(String str, int x, int y) {
34 | name = str;
35 | location = new Location(x, y);
36 | }
37 | }
38 |
39 | /*
40 | /**********************************************************
41 | /* Tests
42 | /**********************************************************
43 | */
44 |
45 | /**
46 | * Simple test to verify that explicit schema mapping works fine
47 | * with unwrapped entities
48 | */
49 | public void testSimpleUnwrappingRoundtrip() throws Exception
50 | {
51 | final String CSV = "Joe,15,27\n";
52 | ObjectMapper mapper = mapperForCsv();
53 | CsvSchema schema = CsvSchema.builder()
54 | .addColumn("name")
55 | .addColumn("loc.x")
56 | .addColumn("loc.y")
57 | .build();
58 | Unwrapping wrapper = mapper.reader(schema).forType(Unwrapping.class).readValue(CSV);
59 | assertNotNull(wrapper);
60 | assertNotNull(wrapper.location);
61 | assertEquals(15, wrapper.location.x);
62 | assertEquals(27, wrapper.location.y);
63 |
64 | // should also write out the same way
65 | assertEquals(CSV, mapper.writer(schema).writeValueAsString(wrapper));
66 | }
67 |
68 |
69 | /**
70 | * Another simple test, but this time auto-generating Schema from
71 | * POJO.
72 | */
73 | /* NOTE: the problem here is that Unwrapped properties should be further
74 | * detected to find sub-properties -- but that information is not yet
75 | * available via BeanProperty/POJOPropertyBuilder. But it needs to be
76 | * made; and when this occurs, we can handle this case reasonably well.
77 | */
78 | public void testSimpleWithAutoSchema() throws Exception
79 | {
80 | final String CSV = "Henry,28,12\n";
81 | CsvMapper mapper = mapperForCsv();
82 | CsvSchema schema = mapper.schemaFor(Unwrapping.class);
83 |
84 | Unwrapping wrapper = mapper.reader(schema).forType(Unwrapping.class).readValue(CSV);
85 | assertNotNull(wrapper);
86 | assertNotNull(wrapper.location);
87 | assertEquals(28, wrapper.location.x);
88 | assertEquals(12, wrapper.location.y);
89 |
90 | // should also write out the same way
91 | assertEquals(CSV, mapper.writer(schema).writeValueAsString(wrapper));
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/properties/src/test/java/com/fasterxml/jackson/dataformat/javaprop/SimpleGenerationTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.javaprop;
2 |
3 | import java.util.Properties;
4 |
5 | public class SimpleGenerationTest extends ModuleTestBase
6 | {
7 | private final JavaPropsMapper MAPPER = mapperForProps();
8 |
9 | public void testSimpleEmployee() throws Exception
10 | {
11 | FiveMinuteUser input = new FiveMinuteUser("Bob", "Palmer", true, Gender.MALE,
12 | new byte[] { 1, 2, 3, 4 });
13 | String output = MAPPER.writeValueAsString(input);
14 | assertEquals("firstName=Bob\n"
15 | +"lastName=Palmer\n"
16 | +"gender=MALE\n"
17 | +"verified=true\n"
18 | +"userImage=AQIDBA==\n"
19 | ,output);
20 | Properties props = MAPPER.writeValueAsProperties(input);
21 | assertEquals(5, props.size());
22 | assertEquals("true", props.get("verified"));
23 | assertEquals("MALE", props.get("gender"));
24 | }
25 |
26 | public void testSimpleRectangle() throws Exception
27 | {
28 | Rectangle input = new Rectangle(new Point(1, -2), new Point(5, 10));
29 | String output = MAPPER.writeValueAsString(input);
30 | assertEquals("topLeft.x=1\n"
31 | +"topLeft.y=-2\n"
32 | +"bottomRight.x=5\n"
33 | +"bottomRight.y=10\n"
34 | ,output);
35 | Properties props = MAPPER.writeValueAsProperties(input);
36 | assertEquals(4, props.size());
37 | assertEquals("5", props.get("bottomRight.x"));
38 | }
39 |
40 | public void testRectangleWithCustomKeyValueSeparator() throws Exception
41 | {
42 | JavaPropsSchema schema = JavaPropsSchema.emptySchema()
43 | .withKeyValueSeparator(": ");
44 | Rectangle input = new Rectangle(new Point(1, -2), new Point(5, 10));
45 | String output = MAPPER.writer(schema).writeValueAsString(input);
46 | assertEquals("topLeft.x: 1\n"
47 | +"topLeft.y: -2\n"
48 | +"bottomRight.x: 5\n"
49 | +"bottomRight.y: 10\n"
50 | ,output);
51 | Properties props = MAPPER.writeValueAsProperties(input, schema);
52 | assertEquals(4, props.size());
53 | assertEquals("5", props.get("bottomRight.x"));
54 | }
55 |
56 | public void testRectangleWithHeader() throws Exception
57 | {
58 | final String HEADER = "# SUPER IMPORTANT!\n";
59 | JavaPropsSchema schema = JavaPropsSchema.emptySchema()
60 | .withHeader(HEADER);
61 | Rectangle input = new Rectangle(new Point(1, -2), new Point(5, 10));
62 | String output = MAPPER.writer(schema)
63 | .writeValueAsString(input);
64 | assertEquals(HEADER
65 | +"topLeft.x=1\n"
66 | +"topLeft.y=-2\n"
67 | +"bottomRight.x=5\n"
68 | +"bottomRight.y=10\n"
69 | ,output);
70 | }
71 |
72 | public void testRectangleWithIndent() throws Exception
73 | {
74 | JavaPropsSchema schema = JavaPropsSchema.emptySchema()
75 | .withLineIndentation(" ");
76 | Rectangle input = new Rectangle(new Point(1, -2), new Point(5, 10));
77 | String output = MAPPER.writer(schema)
78 | .writeValueAsString(input);
79 | assertEquals(" topLeft.x=1\n"
80 | +" topLeft.y=-2\n"
81 | +" bottomRight.x=5\n"
82 | +" bottomRight.y=10\n"
83 | ,output);
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/TypeIdTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.yaml;
2 |
3 | import com.fasterxml.jackson.annotation.*;
4 |
5 | import com.fasterxml.jackson.databind.ObjectMapper;
6 | import com.fasterxml.jackson.databind.util.TokenBuffer;
7 |
8 | public class TypeIdTest extends ModuleTestBase
9 | {
10 | @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY,
11 | property = "type")
12 | @JsonSubTypes({ @JsonSubTypes.Type(Impl.class) })
13 | static abstract class Base {
14 | public int a;
15 |
16 | public Base() { }
17 | public Base(int a) {
18 | this.a = a;
19 | }
20 | }
21 |
22 | @JsonTypeName("impl")
23 | static class Impl extends Base {
24 | public Impl() { }
25 | public Impl(int a) { super(a); }
26 | }
27 |
28 | /*
29 | /**********************************************************
30 | /* Test methods
31 | /**********************************************************
32 | */
33 |
34 | public void testNativeSerialization() throws Exception
35 | {
36 | ObjectMapper mapper = newObjectMapper();
37 | String yaml = mapper.writeValueAsString(new Impl(13));
38 | yaml = yaml.trim();
39 | assertEquals("--- !\na: 13", yaml);
40 | }
41 |
42 | public void testNonNativeSerialization() throws Exception
43 | {
44 | YAMLMapper mapper = new YAMLMapper();
45 | String yaml = mapper.writer()
46 | .without(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID)
47 | .writeValueAsString(new Impl(13));
48 | yaml = yaml.trim();
49 | assertEquals("---\ntype: \"impl\"\na: 13", yaml);
50 |
51 | // Let's also round-trip it
52 | Base back = mapper.readValue(yaml, Impl.class);
53 | assertNotNull(back);
54 | assertEquals(Impl.class, back.getClass());
55 | }
56 |
57 | public void testDeserialization() throws Exception
58 | {
59 | /* Looks like there are couple of alternative ways to indicate
60 | * type ids... so let's verify variations we know of.
61 | */
62 | ObjectMapper mapper = newObjectMapper();
63 |
64 | for (String typeId : new String[] {
65 | "--- !",
66 | "--- !impl",
67 | "!",
68 | "!impl",
69 | // 04-May-2014, tatu: I _think_ we should support this too but...
70 | // "---\nTYPE: impl\n",
71 | }) {
72 | final String input = typeId + "\na: 13";
73 | Base result = mapper.readValue(input, Base.class);
74 | _verify(result);
75 | }
76 | }
77 |
78 | public void testRoundtripWithBuffer() throws Exception
79 | {
80 | ObjectMapper mapper = newObjectMapper();
81 | TokenBuffer tbuf = mapper.readValue("--- !impl\na: 13\n", TokenBuffer.class);
82 | assertNotNull(tbuf);
83 | Base result = mapper.readValue(tbuf.asParser(), Base.class);
84 | tbuf.close();
85 | _verify(result);
86 | }
87 |
88 | /*
89 | /**********************************************************
90 | /* Internal helper methods
91 | /**********************************************************
92 | */
93 |
94 | private void _verify(Base result)
95 | {
96 | assertNotNull(result);
97 | assertEquals(Impl.class, result.getClass());
98 | Impl i = (Impl) result;
99 | assertEquals(13, i.a);
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ser/FilteringTest.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.ser;
2 |
3 | import java.io.*;
4 | import java.util.ArrayList;
5 | import java.util.HashSet;
6 | import java.util.List;
7 |
8 | import com.fasterxml.jackson.databind.*;
9 | import com.fasterxml.jackson.databind.introspect.Annotated;
10 | import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
11 | import com.fasterxml.jackson.databind.ser.FilterProvider;
12 | import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
13 | import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
14 | import com.fasterxml.jackson.dataformat.csv.*;
15 |
16 | @SuppressWarnings("serial")
17 | public class FilteringTest extends ModuleTestBase
18 | {
19 | static class Entity {
20 | public String name;
21 | public String unusedFieldBetween;
22 | public String description;
23 | public String unusedField;
24 |
25 | public Entity(String name, String description, String unusedField) {
26 | this.name = name;
27 | this.description = description;
28 | this.unusedField = unusedField;
29 | }
30 | }
31 |
32 | private final static String CSV_FILTER_NAME = "csvFilter";
33 |
34 | static class CsvJacksonWriter {
35 | public void writeObjects(OutputStream outputStream,
36 | List> objects, CsvSchema csvSchema ) throws IOException
37 | {
38 | HashSet columnNames = new HashSet();
39 | for (CsvSchema.Column column : csvSchema) {
40 | columnNames.add( column.getName() );
41 | }
42 |
43 | SimpleBeanPropertyFilter csvReponseFilter =
44 | new SimpleBeanPropertyFilter.FilterExceptFilter(columnNames);
45 | FilterProvider filterProvider = new SimpleFilterProvider().addFilter( CSV_FILTER_NAME, csvReponseFilter );
46 |
47 | CsvMapper csvMapper = CsvMapper.builder()
48 | .annotationIntrospector(new CsvAnnotationIntrospector())
49 | .filterProvider(filterProvider)
50 | .build();
51 |
52 | ObjectWriter objectWriter = csvMapper.writer(csvSchema);
53 | objectWriter.writeValue( outputStream, objects);
54 | }
55 | }
56 |
57 | static class CsvAnnotationIntrospector extends JacksonAnnotationIntrospector {
58 | @Override
59 | public Object findFilterId(Annotated a) {
60 | return CSV_FILTER_NAME;
61 | }
62 | }
63 |
64 | public void testWriteObjects() throws Exception {
65 | List entities = new ArrayList();
66 | entities.add( new Entity("Test entity 1", "Test description 1", "Test unused field"));
67 | entities.add(new Entity("Test entity 2", "Test description 2", "Test unused field"));
68 |
69 | CsvSchema csvSchema = CsvSchema.builder()
70 | .addColumn("name")
71 | .addColumn("description")
72 | .setUseHeader( true )
73 | .build()
74 | .withLineSeparator("\r\n");
75 |
76 | CsvJacksonWriter csvWriter = new CsvJacksonWriter();
77 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
78 | csvWriter.writeObjects(outputStream, entities, csvSchema);
79 |
80 | StringBuffer expectedResults = new StringBuffer();
81 | expectedResults.append( "name,description\r\n" );
82 | expectedResults.append( "\"Test entity 1\",\"Test description 1\"\r\n" );
83 | expectedResults.append( "\"Test entity 2\",\"Test description 2\"\r\n");
84 |
85 | assertEquals( expectedResults.toString(), outputStream.toString() );
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/csv/src/main/java/com/fasterxml/jackson/dataformat/csv/impl/BufferedValue.java:
--------------------------------------------------------------------------------
1 | package com.fasterxml.jackson.dataformat.csv.impl;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * Helper class used for holding values for a while until output
7 | * can proceed in expected order.
8 | */
9 | public abstract class BufferedValue
10 | {
11 | protected BufferedValue() { }
12 |
13 | public abstract void write(CsvEncoder w) throws IOException;
14 |
15 | public static BufferedValue buffered(String v) { return new TextValue(v); }
16 | public static BufferedValue bufferedRaw(String v) { return new RawValue(v); }
17 | public static BufferedValue buffered(int v) { return new IntValue(v); }
18 | public static BufferedValue buffered(long v) { return new LongValue(v); }
19 | public static BufferedValue buffered(double v) { return new DoubleValue(v); }
20 | public static BufferedValue buffered(boolean v) {
21 | return v ? BooleanValue.TRUE : BooleanValue.FALSE;
22 | }
23 |
24 | public static BufferedValue bufferedNull() {
25 | return NullValue.std;
26 | }
27 |
28 | protected final static class TextValue extends BufferedValue
29 | {
30 | private final String _value;
31 |
32 | public TextValue(String v) { _value = v; }
33 |
34 | @Override
35 | public void write(CsvEncoder w) throws IOException {
36 | w.appendValue(_value);
37 | }
38 | }
39 |
40 | /**
41 | * @since 2.5
42 | */
43 | protected final static class RawValue extends BufferedValue
44 | {
45 | private final String _value;
46 |
47 | public RawValue(String v) { _value = v; }
48 |
49 | @Override
50 | public void write(CsvEncoder w) throws IOException {
51 | w.appendRawValue(_value);
52 | }
53 | }
54 |
55 | protected final static class IntValue extends BufferedValue
56 | {
57 | private final int _value;
58 |
59 | public IntValue(int v) { _value = v; }
60 |
61 | @Override
62 | public void write(CsvEncoder w) throws IOException {
63 | w.appendValue(_value);
64 | }
65 | }
66 |
67 | protected final static class LongValue extends BufferedValue
68 | {
69 | private final long _value;
70 |
71 | public LongValue(long v) { _value = v; }
72 |
73 | @Override
74 | public void write(CsvEncoder w) throws IOException {
75 | w.appendValue(_value);
76 | }
77 | }
78 |
79 | protected final static class DoubleValue extends BufferedValue
80 | {
81 | private final double _value;
82 |
83 | public DoubleValue(double v) { _value = v; }
84 |
85 | @Override
86 | public void write(CsvEncoder w) throws IOException {
87 | w.appendValue(_value);
88 | }
89 | }
90 |
91 | protected final static class BooleanValue extends BufferedValue
92 | {
93 | public final static BooleanValue FALSE = new BooleanValue(false);
94 | public final static BooleanValue TRUE = new BooleanValue(true);
95 |
96 | private final boolean _value;
97 |
98 | public BooleanValue(boolean v) { _value = v; }
99 |
100 | @Override
101 | public void write(CsvEncoder w) throws IOException {
102 | w.appendValue(_value);
103 | }
104 | }
105 |
106 | protected final static class NullValue extends BufferedValue {
107 | public final static NullValue std = new NullValue();
108 |
109 | private NullValue() { }
110 |
111 | @Override
112 | public void write(CsvEncoder w) throws IOException {
113 | w.appendNull();
114 | }
115 | }
116 | }
117 |
--------------------------------------------------------------------------------