Java JAXB marshaller changes encoding of Can I force JAXB not to convert " into ", for example, when marshalling to XML?Is Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Does a finally block always get executed in Java?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I determine whether an array contains a particular value in Java?How do I convert a String to an int in Java?Creating a memory leak with Java

Plot of a tornado-shaped surface

What is going on with 'gets(stdin)' on the site coderbyte?

Why is so much work done on numerical verification of the Riemann Hypothesis?

Can disgust be a key component of horror?

Mimic lecturing on blackboard, facing audience

Using substitution ciphers to generate new alphabets in a novel

How do you make your own symbol when Detexify fails?

Can I say "fingers" when referring to toes?

Why is it that I can sometimes guess the next note?

Why is the "ls" command showing permissions of files in a FAT32 partition?

Pre-mixing cryogenic fuels and using only one fuel tank

On a tidally locked planet, would time be quantized?

Do the primes contain an infinite almost arithmetic progression?

Does the Linux kernel need a file system to run?

Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?

creating a ":KeepCursor" command

Does the UK parliament need to pass secondary legislation to accept the Article 50 extension

Are Captain Marvel's powers affected by Thanos' actions in Infinity War

Why does the Sun have different day lengths, but not the gas giants?

Picking the different solutions to the time independent Schrodinger eqaution

Can I still be respawned if I die by falling off the map?

Why is this estimator biased?

Did arcade monitors have same pixel aspect ratio as TV sets?

Why would a new[] expression ever invoke a destructor?



Java JAXB marshaller changes encoding of


Can I force JAXB not to convert " into ", for example, when marshalling to XML?Is Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Does a finally block always get executed in Java?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I determine whether an array contains a particular value in Java?How do I convert a String to an int in Java?Creating a memory leak with Java













0















having



String translationXsd = TranslationPropertyHelper.getFileLocation(PropertyKey.TRANSLATE_XSD_FILE);
File translationXsdFile = new File(translationXsd);

SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(translationXsdFile);

JAXBContext jaxbContext = JAXBContext
.newInstance(translationJob.getClass().getPackage().getName());
Marshaller marshaller = jaxbContext.createMarshaller();
OutputStream os = new FileOutputStream(pOutputFile);
XMLOutputFactory xmlof = XMLOutputFactory.newInstance();
XMLStreamWriter xsw = new IndentingXMLStreamWriter(xmlof.createXMLStreamWriter(os));
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, translationXsdFile.getName());
marshaller.setSchema(schema);
marshaller.marshal(translationJob, xsw);
xsw.close();


having a freetext, e.g. "hello i have < b > bold < / b > text inside." in node



generates



<freetextnode>hello i have &lt; b > bold &lt; / b > text inside.</freetextnode>


expectation is:



<freetextnode>hello i have &lt; b &gt; bold &lt; / b &gt; text inside.</freetextnode>


JavaEE 7.










share|improve this question

















  • 2





    What is your question? The > does not need to be escaped since it does not signal anything special to the lexer/parser. If you really need to escape it, do it manually.

    – f1sh
    yesterday











  • @f1sh that's true. but is there i simple option (not rewriting marshaller/beforeMarshaller/afterMarshaller) to do this during marshalling?

    – PdM
    yesterday















0















having



String translationXsd = TranslationPropertyHelper.getFileLocation(PropertyKey.TRANSLATE_XSD_FILE);
File translationXsdFile = new File(translationXsd);

SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(translationXsdFile);

JAXBContext jaxbContext = JAXBContext
.newInstance(translationJob.getClass().getPackage().getName());
Marshaller marshaller = jaxbContext.createMarshaller();
OutputStream os = new FileOutputStream(pOutputFile);
XMLOutputFactory xmlof = XMLOutputFactory.newInstance();
XMLStreamWriter xsw = new IndentingXMLStreamWriter(xmlof.createXMLStreamWriter(os));
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, translationXsdFile.getName());
marshaller.setSchema(schema);
marshaller.marshal(translationJob, xsw);
xsw.close();


having a freetext, e.g. "hello i have < b > bold < / b > text inside." in node



generates



<freetextnode>hello i have &lt; b > bold &lt; / b > text inside.</freetextnode>


expectation is:



<freetextnode>hello i have &lt; b &gt; bold &lt; / b &gt; text inside.</freetextnode>


JavaEE 7.










share|improve this question

















  • 2





    What is your question? The > does not need to be escaped since it does not signal anything special to the lexer/parser. If you really need to escape it, do it manually.

    – f1sh
    yesterday











  • @f1sh that's true. but is there i simple option (not rewriting marshaller/beforeMarshaller/afterMarshaller) to do this during marshalling?

    – PdM
    yesterday













0












0








0








having



String translationXsd = TranslationPropertyHelper.getFileLocation(PropertyKey.TRANSLATE_XSD_FILE);
File translationXsdFile = new File(translationXsd);

SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(translationXsdFile);

JAXBContext jaxbContext = JAXBContext
.newInstance(translationJob.getClass().getPackage().getName());
Marshaller marshaller = jaxbContext.createMarshaller();
OutputStream os = new FileOutputStream(pOutputFile);
XMLOutputFactory xmlof = XMLOutputFactory.newInstance();
XMLStreamWriter xsw = new IndentingXMLStreamWriter(xmlof.createXMLStreamWriter(os));
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, translationXsdFile.getName());
marshaller.setSchema(schema);
marshaller.marshal(translationJob, xsw);
xsw.close();


having a freetext, e.g. "hello i have < b > bold < / b > text inside." in node



generates



<freetextnode>hello i have &lt; b > bold &lt; / b > text inside.</freetextnode>


expectation is:



<freetextnode>hello i have &lt; b &gt; bold &lt; / b &gt; text inside.</freetextnode>


JavaEE 7.










share|improve this question














having



String translationXsd = TranslationPropertyHelper.getFileLocation(PropertyKey.TRANSLATE_XSD_FILE);
File translationXsdFile = new File(translationXsd);

SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(translationXsdFile);

JAXBContext jaxbContext = JAXBContext
.newInstance(translationJob.getClass().getPackage().getName());
Marshaller marshaller = jaxbContext.createMarshaller();
OutputStream os = new FileOutputStream(pOutputFile);
XMLOutputFactory xmlof = XMLOutputFactory.newInstance();
XMLStreamWriter xsw = new IndentingXMLStreamWriter(xmlof.createXMLStreamWriter(os));
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, translationXsdFile.getName());
marshaller.setSchema(schema);
marshaller.marshal(translationJob, xsw);
xsw.close();


having a freetext, e.g. "hello i have < b > bold < / b > text inside." in node



generates



<freetextnode>hello i have &lt; b > bold &lt; / b > text inside.</freetextnode>


expectation is:



<freetextnode>hello i have &lt; b &gt; bold &lt; / b &gt; text inside.</freetextnode>


JavaEE 7.







java jaxb tags






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









PdMPdM

395




395







  • 2





    What is your question? The > does not need to be escaped since it does not signal anything special to the lexer/parser. If you really need to escape it, do it manually.

    – f1sh
    yesterday











  • @f1sh that's true. but is there i simple option (not rewriting marshaller/beforeMarshaller/afterMarshaller) to do this during marshalling?

    – PdM
    yesterday












  • 2





    What is your question? The > does not need to be escaped since it does not signal anything special to the lexer/parser. If you really need to escape it, do it manually.

    – f1sh
    yesterday











  • @f1sh that's true. but is there i simple option (not rewriting marshaller/beforeMarshaller/afterMarshaller) to do this during marshalling?

    – PdM
    yesterday







2




2





What is your question? The > does not need to be escaped since it does not signal anything special to the lexer/parser. If you really need to escape it, do it manually.

– f1sh
yesterday





What is your question? The > does not need to be escaped since it does not signal anything special to the lexer/parser. If you really need to escape it, do it manually.

– f1sh
yesterday













@f1sh that's true. but is there i simple option (not rewriting marshaller/beforeMarshaller/afterMarshaller) to do this during marshalling?

– PdM
yesterday





@f1sh that's true. but is there i simple option (not rewriting marshaller/beforeMarshaller/afterMarshaller) to do this during marshalling?

– PdM
yesterday












1 Answer
1






active

oldest

votes


















1














You need to merge marshalling with com.sun.xml.internal.bind.marshaller.DumbEscapeHandler. From JavaDoc:




Escape everything above the US-ASCII code range. A fallback position.
Works with any JDK, any encoding.




Simple example how to use it:



import com.sun.xml.internal.bind.marshaller.DataWriter;
import com.sun.xml.internal.bind.marshaller.DumbEscapeHandler;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import java.io.PrintWriter;

public class JaxbApp

public static void main(String[] args) throws Exception
FreeTextNode dataFile = new FreeTextNode();
dataFile.setValue("hello i have < b > bold < / b > text inside.");
JAXBContext jaxbContext = JAXBContext.newInstance(FreeTextNode.class);
Marshaller marshaller = jaxbContext.createMarshaller();

PrintWriter printWriter = new PrintWriter(System.out);
DataWriter dataWriter = new DataWriter(printWriter, "UTF-8", DumbEscapeHandler.theInstance);
marshaller.marshal(dataFile, dataWriter);



@XmlRootElement(name = "freetextnode")
class FreeTextNode

private String value;

@XmlValue
public String getValue()
return value;


public void setValue(String value)
this.value = value;




Above code prints:



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<freetextnode>hello i have &lt; b &gt; bold &lt; / b &gt; text inside.</freetextnode>


See also:



  • Can I force JAXB not to convert " into ", for example, when marshalling to XML?

  • DumbEscapeHandler





share|improve this answer























  • A bit too much, since I only need a solution for >, but great solution.

    – PdM
    12 hours ago










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280620%2fjava-jaxb-marshaller-changes-encoding-of-but-not%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You need to merge marshalling with com.sun.xml.internal.bind.marshaller.DumbEscapeHandler. From JavaDoc:




Escape everything above the US-ASCII code range. A fallback position.
Works with any JDK, any encoding.




Simple example how to use it:



import com.sun.xml.internal.bind.marshaller.DataWriter;
import com.sun.xml.internal.bind.marshaller.DumbEscapeHandler;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import java.io.PrintWriter;

public class JaxbApp

public static void main(String[] args) throws Exception
FreeTextNode dataFile = new FreeTextNode();
dataFile.setValue("hello i have < b > bold < / b > text inside.");
JAXBContext jaxbContext = JAXBContext.newInstance(FreeTextNode.class);
Marshaller marshaller = jaxbContext.createMarshaller();

PrintWriter printWriter = new PrintWriter(System.out);
DataWriter dataWriter = new DataWriter(printWriter, "UTF-8", DumbEscapeHandler.theInstance);
marshaller.marshal(dataFile, dataWriter);



@XmlRootElement(name = "freetextnode")
class FreeTextNode

private String value;

@XmlValue
public String getValue()
return value;


public void setValue(String value)
this.value = value;




Above code prints:



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<freetextnode>hello i have &lt; b &gt; bold &lt; / b &gt; text inside.</freetextnode>


See also:



  • Can I force JAXB not to convert " into ", for example, when marshalling to XML?

  • DumbEscapeHandler





share|improve this answer























  • A bit too much, since I only need a solution for >, but great solution.

    – PdM
    12 hours ago















1














You need to merge marshalling with com.sun.xml.internal.bind.marshaller.DumbEscapeHandler. From JavaDoc:




Escape everything above the US-ASCII code range. A fallback position.
Works with any JDK, any encoding.




Simple example how to use it:



import com.sun.xml.internal.bind.marshaller.DataWriter;
import com.sun.xml.internal.bind.marshaller.DumbEscapeHandler;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import java.io.PrintWriter;

public class JaxbApp

public static void main(String[] args) throws Exception
FreeTextNode dataFile = new FreeTextNode();
dataFile.setValue("hello i have < b > bold < / b > text inside.");
JAXBContext jaxbContext = JAXBContext.newInstance(FreeTextNode.class);
Marshaller marshaller = jaxbContext.createMarshaller();

PrintWriter printWriter = new PrintWriter(System.out);
DataWriter dataWriter = new DataWriter(printWriter, "UTF-8", DumbEscapeHandler.theInstance);
marshaller.marshal(dataFile, dataWriter);



@XmlRootElement(name = "freetextnode")
class FreeTextNode

private String value;

@XmlValue
public String getValue()
return value;


public void setValue(String value)
this.value = value;




Above code prints:



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<freetextnode>hello i have &lt; b &gt; bold &lt; / b &gt; text inside.</freetextnode>


See also:



  • Can I force JAXB not to convert " into ", for example, when marshalling to XML?

  • DumbEscapeHandler





share|improve this answer























  • A bit too much, since I only need a solution for >, but great solution.

    – PdM
    12 hours ago













1












1








1







You need to merge marshalling with com.sun.xml.internal.bind.marshaller.DumbEscapeHandler. From JavaDoc:




Escape everything above the US-ASCII code range. A fallback position.
Works with any JDK, any encoding.




Simple example how to use it:



import com.sun.xml.internal.bind.marshaller.DataWriter;
import com.sun.xml.internal.bind.marshaller.DumbEscapeHandler;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import java.io.PrintWriter;

public class JaxbApp

public static void main(String[] args) throws Exception
FreeTextNode dataFile = new FreeTextNode();
dataFile.setValue("hello i have < b > bold < / b > text inside.");
JAXBContext jaxbContext = JAXBContext.newInstance(FreeTextNode.class);
Marshaller marshaller = jaxbContext.createMarshaller();

PrintWriter printWriter = new PrintWriter(System.out);
DataWriter dataWriter = new DataWriter(printWriter, "UTF-8", DumbEscapeHandler.theInstance);
marshaller.marshal(dataFile, dataWriter);



@XmlRootElement(name = "freetextnode")
class FreeTextNode

private String value;

@XmlValue
public String getValue()
return value;


public void setValue(String value)
this.value = value;




Above code prints:



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<freetextnode>hello i have &lt; b &gt; bold &lt; / b &gt; text inside.</freetextnode>


See also:



  • Can I force JAXB not to convert " into ", for example, when marshalling to XML?

  • DumbEscapeHandler





share|improve this answer













You need to merge marshalling with com.sun.xml.internal.bind.marshaller.DumbEscapeHandler. From JavaDoc:




Escape everything above the US-ASCII code range. A fallback position.
Works with any JDK, any encoding.




Simple example how to use it:



import com.sun.xml.internal.bind.marshaller.DataWriter;
import com.sun.xml.internal.bind.marshaller.DumbEscapeHandler;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import java.io.PrintWriter;

public class JaxbApp

public static void main(String[] args) throws Exception
FreeTextNode dataFile = new FreeTextNode();
dataFile.setValue("hello i have < b > bold < / b > text inside.");
JAXBContext jaxbContext = JAXBContext.newInstance(FreeTextNode.class);
Marshaller marshaller = jaxbContext.createMarshaller();

PrintWriter printWriter = new PrintWriter(System.out);
DataWriter dataWriter = new DataWriter(printWriter, "UTF-8", DumbEscapeHandler.theInstance);
marshaller.marshal(dataFile, dataWriter);



@XmlRootElement(name = "freetextnode")
class FreeTextNode

private String value;

@XmlValue
public String getValue()
return value;


public void setValue(String value)
this.value = value;




Above code prints:



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<freetextnode>hello i have &lt; b &gt; bold &lt; / b &gt; text inside.</freetextnode>


See also:



  • Can I force JAXB not to convert " into ", for example, when marshalling to XML?

  • DumbEscapeHandler






share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Michał ZioberMichał Ziober

16.6k1269108




16.6k1269108












  • A bit too much, since I only need a solution for >, but great solution.

    – PdM
    12 hours ago

















  • A bit too much, since I only need a solution for >, but great solution.

    – PdM
    12 hours ago
















A bit too much, since I only need a solution for >, but great solution.

– PdM
12 hours ago





A bit too much, since I only need a solution for >, but great solution.

– PdM
12 hours ago



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280620%2fjava-jaxb-marshaller-changes-encoding-of-but-not%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript