11package com .fasterxml .jackson .dataformat .xml ;
22
3+ import java .io .File ;
4+ import java .io .FileOutputStream ;
35import java .io .IOException ;
46import java .io .OutputStream ;
57
911import javax .xml .stream .XMLStreamWriter ;
1012
1113import com .fasterxml .jackson .core .*;
14+ import com .fasterxml .jackson .core .exc .StreamWriteException ;
1215import com .fasterxml .jackson .core .type .TypeReference ;
1316import com .fasterxml .jackson .core .util .ByteArrayBuilder ;
1417import com .fasterxml .jackson .databind .*;
@@ -398,7 +401,7 @@ public void writeValue(XMLStreamWriter w0, Object value) throws IOException {
398401 /**
399402 * Method that can be used to serialize any Java value as
400403 * a byte array.
401-
404+ *
402405 * @param value value to write as XML bytes
403406 * @param encoding character encoding for the XML output
404407 * @return byte array representing the XML output
@@ -418,10 +421,36 @@ public byte[] writeValueAsBytes(Object value, String encoding) throws JsonProces
418421 }
419422 }
420423
424+ /**
425+ * Method that can be used to serialize any Java value as
426+ * XML output, written to File provided.
427+ *
428+ * @param resultFile
429+ * @param value
430+ * @param encoding
431+ * @throws IOException
432+ * @throws StreamWriteException
433+ * @throws DatabindException
434+ * @since 2.16
435+ */
436+ public void writeValue (File resultFile , Object value , String encoding )
437+ throws IOException , StreamWriteException , DatabindException
438+ {
439+ _writeValueAndClose (createGenerator (resultFile , encoding ), value );
440+ }
441+
421442 private JsonGenerator createGenerator (OutputStream out , String encoding ) throws IOException {
422443 this ._assertNotNull ("out" , out );
423444 JsonGenerator g = ((XmlFactory ) _jsonFactory ).createGenerator (out , encoding );
424445 this ._serializationConfig .initialize (g );
425446 return g ;
426447 }
448+
449+ private JsonGenerator createGenerator (File outputFile , String encoding ) throws IOException {
450+ _assertNotNull ("outputFile" , outputFile );
451+ JsonGenerator g = ((XmlFactory ) _jsonFactory ).createGenerator (
452+ new FileOutputStream (outputFile ), encoding );
453+ _serializationConfig .initialize (g );
454+ return g ;
455+ }
427456}
0 commit comments