Class CsvParser
- All Implemented Interfaces:
CsvMetaProvider,RecordReadable
Parses RFC 4180-compliant CSV into collections of beans, maps, or simple values. Each row becomes an element; the header row defines column names.
JSON Parity Features (opt-in):
- Type discriminator — Parse
_typecolumn when present; usebeanDictionary()for polymorphic types. - Byte arrays —
byteArrayFormat(BASE64)orSEMICOLON_DELIMITED; primitive arrays from[1;2;3]. - Nested structures —
allowNestedStructures(true)parses inline{key:val}and[val;val]in cells. - Null marker —
nullValue("<NULL>")(default); cells matching this are parsed as null.
Data Structures Not Supported:
- Parent/inherited properties — Bean hierarchy cannot be reconstructed from flat columns.
- Optional wrappers — Round-trip may differ from tree formats.
Best Supported:
Parsing into Collection of flat beans or maps, or single beans/maps with simple
property types (primitives, strings, numbers, enums, dates, byte arrays, or nested structures when enabled).
Example input (list of maps with a,b):
a,b foo,bar
Complex (list of beans with nested address, flattened):
name,age,address_street,address_city,address_state,tags Alice,30,123 Main St,Boston,MA,"a,b,c"
Notes:
- This class is thread safe and reusable.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.apache.juneau.marshall.parser.ReaderParser
ReaderParser.DefaultBuilderNested classes/interfaces inherited from class org.apache.juneau.marshall.parser.Parser
Parser.Null -
Field Summary
FieldsFields inherited from class org.apache.juneau.marshall.parser.Parser
autoCloseStreams, consumes, debugOutputLines, listener, nulls, trimStrings, unbufferedFields inherited from class org.apache.juneau.marshall.MarshallingContextable
marshallingContextFields inherited from class org.apache.juneau.marshall.Context
CONTEXT_APPLY_FILTER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates a builder from this context object.static CsvParser.Buildercreate()Creates a new builder for this object.Create a session builder based on the properties defined on this context.Returns the format for parsingbyte[]arrays from CSV cells.Returns the language-specific metadata on the specified bean property.getCsvClassMeta(ClassMeta<?> cm) Returns the language-specific metadata on the specified class.Returns the string that denotes null when parsing.Returns a session to use for this context.booleanReturns whether inline{key:val}and[val;val]notation parsing is enabled.booleanStreaming-quality signal queryable before opening a cursor.readRecords(Object input) Convenience delegator that opens aRecordReaderover the input using default session arguments (mirrorsParser.read(Object, Class)).Methods inherited from class org.apache.juneau.marshall.parser.ReaderParser
getStreamCharset, isReaderParser, propertiesMethods inherited from class org.apache.juneau.marshall.parser.Parser
canHandle, createParserBuilder, doRead, getDebugOutputLines, getListener, getMediaTypes, getNulls, getPrimaryMediaType, isAutoCloseStreams, isTrimStrings, isUnbuffered, read, read, read, read, read, read, readArgs, readIntoCollection, readIntoMap, readWithOuterMethods inherited from class org.apache.juneau.marshall.MarshallingContextable
getDurationFormat, getMarshallingContext, getPeriodFormatMethods inherited from class org.apache.juneau.marshall.Context
createBuilder, getAnnotationProvider, init, isDebug, toString
-
Field Details
-
DEFAULT
Default parser, all default settings.
-
-
Constructor Details
-
CsvParser
Constructor.- Parameters:
builder- The builder for this object.
-
-
Method Details
-
create
Creates a new builder for this object.- Returns:
- A new builder.
-
getByteArrayFormat
Returns the format for parsingbyte[]arrays from CSV cells.- Returns:
- The byte array format.
-
isAllowNestedStructures
Returns whether inline{key:val}and[val;val]notation parsing is enabled.- Returns:
- Whether nested structures are allowed.
-
getNullValue
Returns the string that denotes null when parsing.- Returns:
- The null marker.
-
copy
Description copied from class:ContextCreates a builder from this context object.Builders are used to define new contexts (e.g. serializers, parsers) based on existing configurations.
-
createSession
Description copied from class:ContextCreate a session builder based on the properties defined on this context.Use this method for creating sessions where you want to override basic settings. Otherwise, use
Context.getSession()directly.- Overrides:
createSessionin classReaderParser- Returns:
- A new session builder.
-
getCsvBeanPropertyMeta
Description copied from interface:CsvMetaProviderReturns the language-specific metadata on the specified bean property.- Specified by:
getCsvBeanPropertyMetain interfaceCsvMetaProvider- Parameters:
bpm- The bean property to return the metadata on.- Returns:
- The metadata.
-
getCsvClassMeta
Description copied from interface:CsvMetaProviderReturns the language-specific metadata on the specified class.- Specified by:
getCsvClassMetain interfaceCsvMetaProvider- Parameters:
cm- The class to return the metadata on.- Returns:
- The metadata.
-
getSession
Description copied from class:ContextReturns a session to use for this context.Note that subclasses may opt to return a reusable non-modifiable session.
- Overrides:
getSessionin classReaderParser- Returns:
- A new session object.
-
readRecords
Convenience delegator that opens aRecordReaderover the input using default session arguments (mirrorsParser.read(Object, Class)).CSV is naturally row-oriented — each row becomes one record — but the current cursor is buffered (the full row list is materialized at parse); a streaming implementation is a Phase 3b deferred item, so
isRecordStreaming()returnsfalse .The real implementation lives on
CsvParserSession.readRecords(Object). Callers that need request-derived configuration (locale, timezone, schema, swaps) should callcreateSession()and invokeCsvParserSession.readRecords(Object)on the built session instead.- Specified by:
readRecordsin interfaceRecordReadable- Parameters:
input- The input.- Returns:
- A new
RecordReadercursor. - Throws:
IOException- If a problem occurred opening the underlying input.
-
isRecordStreaming
Description copied from interface:RecordReadableStreaming-quality signal queryable before opening a cursor.- Specified by:
isRecordStreamingin interfaceRecordReadable- Returns:
true ifRecordReadable.readRecords(Object)returns an O(1)-memory streaming cursor;false for buffered (whole-value) formats backed byRecordAdapter.
-