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

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현