final CsvSchema csvSchema = mapper.typedSchemaFor(ApiError.class).withHeader(); final ApiError apiError = ApiError.create(genericError.message()); mapper.writerFor(ApiError.class).with(csvSchema).writeValue(entityStream, apiError); } else { final CsvSchema csvSchema = mapper.typedSchemaFor(type).withHeader(); mapper.writerFor(type).with(csvSchema).writeValue(entityStream, genericError);
/** * Convenience method which is functionally equivalent to: *<pre> * writer(pojoType).with(typedSchemaFor(pojoType)); *</pre> * that is, constructs a {@link ObjectWriter} which both binds to * specified type and uses "strict" {@link CsvSchema} introspected from * specified type (one where typing is inferred). */ public ObjectWriter writerWithTypedSchemaFor(Class<?> pojoType) { JavaType type = constructType(pojoType); // sanity check as per javadoc above if (type.isArrayType() || type.isCollectionLikeType()) { throw new IllegalArgumentException("Type can NOT be a Collection or array type"); } return writerFor(type).with(typedSchemaFor(type)); }
/** * Convenience method which is functionally equivalent to: *<pre> * writer(pojoType).with(typedSchemaFor(pojoType)); *</pre> * that is, constructs a {@link ObjectWriter} which both binds to * specified type and uses "strict" {@link CsvSchema} introspected from * specified type (one where typing is inferred). */ public ObjectWriter writerWithTypedSchemaFor(Class<?> pojoType) { JavaType type = constructType(pojoType); // sanity check as per javadoc above if (type.isArrayType() || type.isCollectionLikeType()) { throw new IllegalArgumentException("Type can NOT be a Collection or array type"); } return writerFor(type).with(typedSchemaFor(type)); }
/** * Convenience method which is functionally equivalent to: *<pre> * writer(pojoType).with(schemaFor(pojoType)); *</pre> * that is, constructs a {@link ObjectWriter} which both binds to * specified type and uses "loose" {@link CsvSchema} introspected from * specified type (one without strict inferred typing). *<p> * @param pojoType Type used both for data-binding (result type) and for * schema introspection. NOTE: must NOT be an array or Collection type, since * these only make sense for data-binding (like arrays of objects to bind), * but not for schema construction (no root-level CSV types can be mapped to arrays * or Collections) */ public ObjectWriter writerWithSchemaFor(Class<?> pojoType) { JavaType type = constructType(pojoType); // sanity check as per javadoc above if (type.isArrayType() || type.isCollectionLikeType()) { throw new IllegalArgumentException("Type can NOT be a Collection or array type"); } return writerFor(type).with(schemaFor(type)); }
/** * Convenience method which is functionally equivalent to: *<pre> * writer(pojoType).with(schemaFor(pojoType)); *</pre> * that is, constructs a {@link ObjectWriter} which both binds to * specified type and uses "loose" {@link CsvSchema} introspected from * specified type (one without strict inferred typing). *<p> * @param pojoType Type used both for data-binding (result type) and for * schema introspection. NOTE: must NOT be an array or Collection type, since * these only make sense for data-binding (like arrays of objects to bind), * but not for schema construction (no root-level CSV types can be mapped to arrays * or Collections) */ public ObjectWriter writerWithSchemaFor(Class<?> pojoType) { JavaType type = constructType(pojoType); // sanity check as per javadoc above if (type.isArrayType() || type.isCollectionLikeType()) { throw new IllegalArgumentException("Type can NOT be a Collection or array type"); } return writerFor(type).with(schemaFor(type)); }