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> * reader(pojoType).withSchema(typedSchemaFor(pojoType)); *</pre> * that is, constructs a {@link ObjectReader} which both binds to * specified type and uses "strict" {@link CsvSchema} introspected from * specified type (one where typing is inferred). */ public ObjectReader readerWithTypedSchemaFor(Class<?> pojoType) { JavaType type = constructType(pojoType); // sanity check: not useful for structured types, since // schema type will need to differ from data-bind type if (type.isArrayType() || type.isCollectionLikeType()) { throw new IllegalArgumentException("Type can NOT be a Collection or array type"); } return readerFor(type).with(typedSchemaFor(type)); }
/** * Convenience method which is functionally equivalent to: *<pre> * reader(pojoType).withSchema(typedSchemaFor(pojoType)); *</pre> * that is, constructs a {@link ObjectReader} which both binds to * specified type and uses "strict" {@link CsvSchema} introspected from * specified type (one where typing is inferred). */ public ObjectReader readerWithTypedSchemaFor(Class<?> pojoType) { JavaType type = constructType(pojoType); // sanity check: not useful for structured types, since // schema type will need to differ from data-bind type if (type.isArrayType() || type.isCollectionLikeType()) { throw new IllegalArgumentException("Type can NOT be a Collection or array type"); } return readerFor(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(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> * reader(pojoType).withSchema(typedSchemaFor(pojoType)); *</pre> * that is, constructs a {@link ObjectReader} which both binds to * specified type and uses "strict" {@link CsvSchema} introspected from * specified type (one where typing is inferred). */ public ObjectReader readerWithTypedSchemaFor(Class<?> pojoType) { JavaType type = constructType(pojoType); /* sanity check: not useful for structured types, since * schema type will need to differ from data-bind type */ if (type.isArrayType() || type.isCollectionLikeType()) { throw new IllegalArgumentException("Type can NOT be a Collection or array type"); } return reader(type).with(typedSchemaFor(type)); }