Are you on a Mac, by chance? I ran into a similar issue a couple weeks ago with a project that would build off the command line but failed from NetBeans. The issue turned out to be a JDK bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8003228
The solution was to add the following line to the top of netbeans.conf: export LC_CTYPE=UTF-8 Cheers, Steven On Tue, Feb 19, 2013 at 5:10 AM, Jörg Schaible <[email protected]>wrote: > Hi, > > Lynton wrote: > > > [This is the java code] > > > > DadosPessoaisTO dados = new DadosPessoaisTO(); > > dados.setNome("FlÁvio"); > > well, this already implies that you Java source code is in UTF-8 and that > you have told your compiler that your source is in UTF-8. You should use > \uXXXX encoding here. > > > String a = formatTransferObject(dados); > > System.out.println(a); > > DadosPessoaisTO dadosConvert = parseTransferObject(a); > > System.out.println(dadosConvert.getNome()); > > > > > > public static String formatTransferObject(Object to) { > > > > ByteArrayOutputStream bytes = new ByteArrayOutputStream(); > > > > > > Writer writer = new java.io.OutputStreamWriter(bytes, > > Charset.forName("UTF-8")); > > > > > > new XStream(new StaxDriver()).toXML(to, writer); > > > > > > return new String(bytes.toByteArray()); > > ... and this last statement implies that your OS runs with UTF-8 as system > encoding ... use "new String(bytes.toByteArray(), "UTF-8")" instead. > > > } > > > > @SuppressWarnings("unchecked") > > public static <TO> TO parseTransferObject(String xml) { > > try { > > return (TO) new XStream(new StaxDriver()).fromXML(new > > InputStreamReader(new java.io.ByteArrayInputStream(xml.getBytes()), > > "UTF-8")); > > ... your code again implies a system encoding of UTF-8, please use > "xml.getBytes("UTF-8")" instead. > > > > > } catch (UnsupportedEncodingException e) { > > throw new RuntimeException(e); > > } > > } > > > > [this is result of the FIRST system out] > > > > <?xml version="1.0" encoding="UTF-8"?> > > > <br.com.br.aarh.dadospessoais.to.DadosPessoaisTO><nome>FlÃ?vio</nome><sexo> > > </sexo><estadoCivil></estadoCivil><nascimento><pais></pais></nascimento> > > <nacionalidade></nacionalidade><comprovante></comprovante> > > <comprovanteDocumentoPessoalDTO></comprovanteDocumentoPessoalDTO> > > </br.com.br.aarh.dadospessoais.to.DadosPessoaisTO> > > > > [this is the result of the second system out] > > Fl??vio > > Cheers, > Jörg > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > >
