JSefa is a simple library for stream-based serialization of java objects to XML, CSV, or FLR and back again using an iterator-style interface independent of the serialization format. Current implementation for XML is based on JSR 173 (Stax).
Be the first to post a text review of JSefa. Rate and review a project by clicking thumbs up or thumbs down in the right column.
Since the first official version of JSefa some new features have found their way into this new release. Among others are validation for all format types and line filters for CSV and FLR. See http://jsefa.sourceforge.net/changes-report.html for a list of all changes.
* Bugfixes * Handling of consecutive events of type CHARACTERS fixed (low level XML deserialization) The bug appeared using the sun implementation of Stax but not using Woodstox as the latter seems to combine the characters to one CHARACTER event. * Usage of primitive simple types (int, boolean etc. in contrast to Integer, Boolean etc.) for XML attributes and XML text contents fixed * Handling of multiple subrecord lists fixed (high level CSV/FLR) * Serialization of a CSV field with QuoteMode.ON_DEMAND whereas the field content starts with a quote char failed. This is fixed now. * Deserialization of a CSV field with more than one line break failed - only the first was read and the rest were skipped. This is fixed now. * Changed behavior * The default line break is now the system property line.property - was line feed (\n) before * xsi:type attribute default behavior Say you have a class Customer with the two subclasses BusinessCustomer and PrivateCustomer and another class Order with a field customer of type Customer. Further this field shall map to an xml element called <customer>. Then the deserialization of such a <customer> element <without> an xsi:type attribute will result in creating an instance of class Customer. It was not possible to deserialize a <customer> element without an xsi:type attribute before - one was forced to supply the xsi:type attribute as no default was assumed. * CsvLowLevelDeserializer.nextField now returns null if no next field exists (was the empty string before), the empty string if the next field is empty and a non empty field value in all other cases. * The default quote mode for CSV fields is now QuoteMode.ON_DEMAND - was QuoteMode.NEVER before. This new default is compliant to the RFC4180 and to what most users would expect. If you need the old default, you can set this once for the JVM (before creating the first Configuration) with InitialConfiguration.set(CsvInitialConfigurationParameters.DEFAUT_QUOTE_MODE, QuoteMode.NEVER). * FlrLowLevelDeserializer no longer throws an exception if a record contains less fields than expected. Instead the missing fields are set to null. * New Features * Validation (XML/CSV/FLR) You can now define that values are required or not using the annotation parameter "required". Furthermore you can impose constraints on the values using the annotation parameter "constraints", e. g. constraints = {"minLength=1", "maxLength=3"} for constraining the length of a String. Finally it is possible to define Validators on your own. See the interface Validator as the starting point for further investigations and the ValueValidationOnDeserializationTest, especially the inner class ComplexElementDTOValidator for an example of a user defined validator. Of course it is possible to define whether validation should be performed or not. * SimpleListConverter (XML/CSV/FLR) You can now map a list of simple types (e. g. list of integers) to a simple type of the exchange format (called simple list type). E. g. the serialization of a List<Integer> field containing the values 1,2 and 3 may result in "<element>1,2,3</element>". Of course you can change the delimiter with the annotation parameter "format", e. g. @XmlElement(..., format=" ") for space as the delimiter. This feature is especially useful when handling CSV files with a list type field whereas the delimiter for the list items differs from the field delimiter (e. g. "a;b1,b2,b3;c" has 3 fields whereas the second is a list with three elements). See the inner annotation SimpleListItem used for the annotation parameter listItem of several annotations (e. g. XmlElement, CsvField) and the SimpleListTypeTest. * InputPosition (XML/CSV/FLR deserialization) Each LowLevelDeserializer provides information about the current position within the input stream. This consists of the line number and column number. Each high level Deserializer provides a convenient method to retrieve this information from the underlying LowLevelDeserializer. Additionally a DeserializationException provides the method getInputPosition as well thus providing information about the error location. * Support for Set and Queue (XML/CSV/FLR) JSefa now supports fields of type Set and Queue. They will be handled exactly like fields of type List. * Flush operation for Serializer (XML/CSV/FLR) Each Serializer now supports flushing the buffer. * CDATA (XML serialization) You can now define that the content of an element should be a CDATA section. The default is to use entity references like < to escape characters. See the enumeration TextMode and its use for several annotation paramters (e. g. XmlElement.textMode) as well as the TextModeTest. <Note>: The XmlLowLevelSerializer.writeText method now has a second parameter of type TextMode. In the rare case you use this method just add TextMode.IMPLICIT as the second argument to every call of this method. * DOCTYPE declaration (XML serialization) Using the low level serializer you can now write out a DOCTYPE declaration. * LineFilter (CSV/FLR deserialization) A line filter allows for filtering out lines during deserialization. These lines can also be stored for later retrieval. The typical use case of a line filter is to filter out and retrieve headers and footers of CSV/FLR files. See LineFilter, RbfConfiguration.setLineFilter, RbfDeserializer.getStoredLines, HeaderAndFooterFilterTest etc. * Support for special record delimiters (CSV/FLR) Typically a record is delimited by a line break. But some formats have a special record delimiter resulting in a file with one big line separated by a special character - the special record delimiter. JSefa now supports such formats (even with header and footer). * Accessor to LowLevelSerializer (CSV/FLR serialization) CsvSerializer and FlrSerializer now have a method getLowLevelSerializer to access the underlying low level serializer. Such a method existed for XmlSerializer already. * QuoteMode.NEVER now supports escaping of line breaks and record delimiters (CSV) The content of a CSV field with QuoteMode.NEVER can now contain line breaks and record delimiters. * Support for special "no value" string (CSV) By default the empty string is used to denote that a CSV field has no value. Now one can configure that a special string (e. g. "NULL") should be used instead. See the annotation parameter CsvField.noValue as well as CsvConfiguration.getDefaultNoValueString, CsvConfiguration.setDefaultNoValueString and CsvInitialConfigurationParameters.DEFAULT_NO_VALUE_STRING. * New Samples * samples/csv/header Demonstrates how to create a CSV file with a header and how to read in such a file using a LineFilter. * samples/csv/yellow_pages Demonstrates the use of sub records and sub record lists (for CSV). * samples/flr/yellow_pages Demonstrates the use of sub records and sub record lists (for FLR). * Diverse * The javassist based ObjectAccessorProvider is no longer part of the JSefa distribution. The reflection based ObjectAccessorProvider is now fast enough so that there is no need to support the one based on javassist any longer.
* Bugfixes * Handling of consecutive events of type CHARACTERS fixed (low level XML deserialization) The bug appeared using the sun implementation of Stax but not using Woodstox as the latter seems to combine the characters to one CHARACTER event. * Usage of primitive simple types (int, boolean etc. in contrast to Integer, Boolean etc.) for XML attributes and XML text contents fixed * Handling of multiple subrecord lists fixed (high level CSV/FLR) * Serialization of a CSV field with QuoteMode.ON_DEMAND whereas the field content starts with a quote char failed. This is fixed now. * Deserialization of a CSV field with more than one line break failed - only the first was read and the rest were skipped. This is fixed now. * Changed behavior * The default line break is now the system property line.property - was line feed (\n) before * xsi:type attribute default behavior Say you have a class Customer with the two subclasses BusinessCustomer and PrivateCustomer and another class Order with a field customer of type Customer. Further this field shall map to an xml element called <customer>. Then the deserialization of such a <customer> element <without> an xsi:type attribute will result in creating an instance of class Customer. It was not possible to deserialize a <customer> element without an xsi:type attribute before - one was forced to supply the xsi:type attribute as no default was assumed. * CsvLowLevelDeserializer.nextField now returns null if no next field exists (was the empty string before), the empty string if the next field is empty and a non empty field value in all other cases. * The default quote mode for CSV fields is now QuoteMode.ON_DEMAND - was QuoteMode.NEVER before. This new default is compliant to the RFC4180 and to what most users would expect. If you need the old default, you can set this once for the JVM (before creating the first Configuration) with InitialConfiguration.set(CsvInitialConfigurationParameters.DEFAUT_QUOTE_MODE, QuoteMode.NEVER). * FlrLowLevelDeserializer no longer throws an exception if a record contains less fields than expected. Instead the missing fields are set to null. * New Features * Validation (XML/CSV/FLR) You can now define that values are required or not using the annotation parameter "required". Furthermore you can impose constraints on the values using the annotation parameter "constraints", e. g. constraints = {"minLength=1", "maxLength=3"} for constraining the length of a String. Finally it is possible to define Validators on your own. See the interface Validator as the starting point for further investigations and the ValueValidationOnDeserializationTest, especially the inner class ComplexElementDTOValidator for an example of a user defined validator. Of course it is possible to define whether validation should be performed or not. * SimpleListConverter (XML/CSV/FLR) You can now map a list of simple types (e. g. list of integers) to a simple type of the exchange format (called simple list type). E. g. the serialization of a List<Integer> field containing the values 1,2 and 3 may result in "<element>1,2,3</element>". Of course you can change the delimiter with the annotation parameter "format", e. g. @XmlElement(..., format=" ") for space as the delimiter. This feature is especially useful when handling CSV files with a list type field whereas the delimiter for the list items differs from the field delimiter (e. g. "a;b1,b2,b3;c" has 3 fields whereas the second is a list with three elements). See the inner annotation SimpleListItem used for the annotation parameter listItem of several annotations (e. g. XmlElement, CsvField) and the SimpleListTypeTest. * InputPosition (XML/CSV/FLR deserialization) Each LowLevelDeserializer provides information about the current position within the input stream. This consists of the line number and column number. Each high level Deserializer provides a convenient method to retrieve this information from the underlying LowLevelDeserializer. Additionally a DeserializationException provides the method getInputPosition as well thus providing information about the error location. * Support for Set and Queue (XML/CSV/FLR) JSefa now supports fields of type Set and Queue. They will be handled exactly like fields of type List. * Flush operation for Serializer (XML/CSV/FLR) Each Serializer now supports flushing the buffer. * CDATA (XML serialization) You can now define that the content of an element should be a CDATA section. The default is to use entity references like < to escape characters. See the enumeration TextMode and its use for several annotation paramters (e. g. XmlElement.textMode) as well as the TextModeTest. <Note>: The XmlLowLevelSerializer.writeText method now has a second parameter of type TextMode. In the rare case you use this method just add TextMode.IMPLICIT as the second argument to every call of this method. * DOCTYPE declaration (XML serialization) Using the low level serializer you can now write out a DOCTYPE declaration. * LineFilter (CSV/FLR deserialization) A line filter allows for filtering out lines during deserialization. These lines can also be stored for later retrieval. The typical use case of a line filter is to filter out and retrieve headers and footers of CSV/FLR files. See LineFilter, RbfConfiguration.setLineFilter, RbfDeserializer.getStoredLines, HeaderAndFooterFilterTest etc. * Support for special record delimiters (CSV/FLR) Typically a record is delimited by a line break. But some formats have a special record delimiter resulting in a file with one big line separated by a special character - the special record delimiter. JSefa now supports such formats (even with header and footer). * Accessor to LowLevelSerializer (CSV/FLR serialization) CsvSerializer and FlrSerializer now have a method getLowLevelSerializer to access the underlying low level serializer. Such a method existed for XmlSerializer already. * QuoteMode.NEVER now supports escaping of line breaks and record delimiters (CSV) The content of a CSV field with QuoteMode.NEVER can now contain line breaks and record delimiters. * Support for special "no value" string (CSV) By default the empty string is used to denote that a CSV field has no value. Now one can configure that a special string (e. g. "NULL") should be used instead. See the annotation parameter CsvField.noValue as well as CsvConfiguration.getDefaultNoValueString, CsvConfiguration.setDefaultNoValueString and CsvInitialConfigurationParameters.DEFAULT_NO_VALUE_STRING. * New Samples * samples/csv/header Demonstrates how to create a CSV file with a header and how to read in such a file using a LineFilter. * samples/csv/yellow_pages Demonstrates the use of sub records and sub record lists (for CSV). * samples/flr/yellow_pages Demonstrates the use of sub records and sub record lists (for FLR). * Diverse * The javassist based ObjectAccessorProvider is no longer part of the JSefa distribution. The reflection based ObjectAccessorProvider is now fast enough so that there is no need to support the one based on javassist any longer.
Be the first person to add a text review.
Copyright © 2010 Geeknet, Inc. All rights reserved. Terms of Use
Thanks for your rating!
Would you also like to write a review?
Thanks for your review!
Get credit for your review by logging in via OpenID. Click your account provider: