JSON中的长字符串值

时间:2013-04-15 11:59:14

标签: json jersey jackson jax-rs

我正为MessageBodyWriter撰写java.util.Properties

@Override
public void writeTo(final Properties t, final Class<?> type,
                    final Type genericType, final Annotation[] annotations,
                    final MediaType mediaType,
                    final MultivaluedMap<String, Object> httpHeaders,
                    final OutputStream entityStream)
    throws IOException, WebApplicationException {

    LOGGER.log(Level.INFO, "writeTo({0}, {1}, {2}, {3}, {4}, {5}, {6})",
               new Object[]{t, type, genericType, annotations, mediaType,
                            httpHeaders, entityStream});

    if (MediaType.APPLICATION_XML_TYPE.isCompatible(mediaType)) {
        t.storeToXML(entityStream, null);
        return;
    }

    if (MediaType.APPLICATION_JSON_TYPE.isCompatible(mediaType)) {

        final JsonGenerator generator =
            JSON_FACTORY.createGenerator(entityStream);

        generator.writeStartObject();

        for (String stringPropertyName : t.stringPropertyNames()) {
            generator.writeFieldName(stringPropertyName);
            generator.writeString(t.getProperty(stringPropertyName));
            //generator.writeStringField(stringPropertyName,
            //                           t.getProperty(stringPropertyName));
        }

        generator.writeEndObject();

        return;
    }

    throw new WebApplicationException(
        Response.Status.UNSUPPORTED_MEDIA_TYPE);

}

当我使用application/xml请求时,它似乎工作正常。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
  <entry key="java.library.path">C:\Program Files\Java\jdk1.7.0_17\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Programs\cygwin\usr\local\bin;C:\Programs\cygwin\bin;C:\Program Files (x86)\PHP;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Program Files (x86)\Wizvera\Delfino;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files\CollabNet\Subversion Client;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Programs\cygwin\bin;C:\Programs\apache-maven-3.0.5\bin;E:\programs\apache-ivy-2.3.0\bin;E:\programs\apache-ant-1.9.0\bin;C:\Program Files\Java\jdk1.7.0_17\bin;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\QuickTime\QTSystem;C:\Program Files\SlikSvn\bin;C:\Programs\emacs-24.2\bin;C:\Program Files (x86)\ESTsoft\ALZip;C:\Programs\android-sdk-windows\tools;C:\Programs\android-sdk-windows\platform-tools;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Common Files\Autodesk Shared;C:\Program Files\Common Files\Autodesk Shared;C:\Program Files (x86)\Graphviz2.26.3\bin;C:\Programs\android-sdk-windows\tools;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn;C:\Program Files\Microsoft SQL Server\100\Tools\Binn;C:\Program Files\Microsoft SQL Server\100\DTS\Binn;C:\Programs\db-derby-10.8.2.2-bin\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\QuickTime\QTSystem;C:\Program Files\Microsoft Windows Performance Toolkit;C:\Program Files\Microsoft SDKs\Windows\v7.1\bin;C:\Program Files (x86)\Microsoft WSE\v3.0\Tools;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files (x86)\Graphviz 2.28\bin;C:\Program Files (x86)\ESTsoft\ALSee\x64;.</entry>
</properties>

但是当我尝试在application/json条目上java.library.path输出结果修剪时。

{
    "java.vendor": "Oracle Corporation",
    "sun.java.launcher": "SUN_STANDARD",
    "catalina.base": "C:\\Programs\\cygwin\\tmp\\gfembed1008540206574562263tmp",
    "sun.management.compiler": "HotSpot 64-Bit Tiered Compilers",
    "catalina.useNaming": "false",
    "os.name": "Windows 7",
    "sun.boot.class.path": "C:\\Program Files\\Java\\jdk1.7.0_17\\jre\\lib\\resources.jar;C:\\Program Files\\Java\\jdk1.7.0_17\\jre\\lib\\rt.jar;C:\\Program Files\\Java\\jdk1.7.0_17\\jre\\lib\\sunrsasign.jar;C:\\Program Files\\Java\\jdk1.7.0_17\\jre\\lib\\jsse.jar;C:\\Program Files\\Java\\jdk1.7.0_17\\jre\\lib\\jce.jar;C:\\Program Files\\Java\\jdk1.7.0_17\\jre\\lib\\charsets.jar;C:\\Program Files\\Java\\jdk1.7.0_17\\jre\\lib\\jfr.jar;C:\\Program Files\\Java\\jdk1.7.0_17\\jre\\classes",
    "javax.security.jacc.PolicyConfigurationFactory.provider": "com.sun.enterprise.security.jacc.provider.SimplePolicyConfigurationFactory",
    "user.country.format": "KR",
    "sun.desktop": "windows",
    "java.vm.specification.vendor": "Oracle Corporation",
    "java.runtime.version": "1.7.0_17-b02",
    "javax.net.ssl.keyStore": "C:\\Programs\\cygwin\\tmp\\gfembed1008540206574562263tmp/config/keystore.jks",
    "user.name": "onacit",
    "web.home": "C:\\Programs\\cygwin\\tmp\\gfembed1008540206574562263tmp\\modules\\web",
    "shared.loader": "${catalina.home}/shared/classes,${catalina.home}/shared/lib/*.jar",
    "user.language.format": "ko",
    "guice.disable.misplaced.annotation.check": "true",
    "user.language": "en",
    "sun.boot.library.path": "C:\\Program Files\\Java\\jdk1.7.0_17\\jre\\bin",
    "com.sun.aas.javaRoot": "C:\\Program Files\\Java\\jdk1.7.0_17\\jre",
    "classworlds.conf": "C:\\Programs\\apache-maven-3.0.5/bin/m2.conf",
    "java.version": "1.7.0_17",
    "com.sun.aas.instanceRootURI": "file:/C:/Programs/cygwin/tmp/gfembed1008540206574562263tmp/",
    "user.timezone": "Asia/Seoul",
    "sun.arch.data.model": "64",
    "javax.rmi.CORBA.UtilClass": "com.sun.corba.ee.impl.javax.rmi.CORBA.Util",
    "java.endorsed.dirs": "C:\\Program Files\\Java\\jdk1.7.0_17\\jre\\lib\\endorsed",
    "com.sun.aas.installRoot": "C:\\Programs\\cygwin\\tmp\\gfembed1008540206574562263tmp",
    "sun.cpu.isalist": "amd64",
    "sun.jnu.encoding": "MS949",
    "file.encoding.pkg": "sun.io",
    "package.access": "",
    "file.separator": "\\",
"java.specification.name":"JavaPlatformAPISpecification",
"java.class.version":"51.0",
"user.country":"US",
"java.home":"C: \\ProgramFiles\\Java\\jdk1.7.0_17\\jre",
"java.vm.info":"mixedmode",
"os.version":"6.1",
"com.sun.aas.productRoot":"C: \\Programs\\cygwin\\tmp",
"org.omg.CORBA.ORBSingletonClass":"com.sun.corba.ee.impl.orb.ORBSingleton",
"com.sun.aas.installRootURI":"file: /C: /Programs/cygwin/tmp/gfembed1008540206574562263tmp/",
"path.separator":";",
"java.vm.version":"23.7-b01",
"user.variant":"",
"java.awt.printerjob":"sun.awt.windows.WPrinterJob",
"sun.io.unicode.encoding":"UnicodeLittle",
"com.sun.aas.hostName":"onacit-PC",
"awt.toolkit":"sun.awt.windows.WToolkit",
"package.definition":"",
"user.script":"",
"user.home":"C: \\Users\\onacit",
"com.sun.aas.instanceName":"server",
"com.sun.aas.configRoot":"C: \\Programs\\cygwin\\tmp\\gfembed1008540206574562263tmp\\config",
"java.specification.vendor":"OracleCorporation",
"java.library.path":"C: \\ProgramFiles\\Java\\jdk1.7.0_17\\bin;C: \\Windows\\Sun\\Java\\bin;C: \\Windows\\system32;C: \\Windows;C: \\Programs\\cygwin\\usr\\local\\bin;C: \\Programs\\cygwin\\bin;C: \\ProgramFiles(x86)\\PHP;C: \\ProgramFiles(x86)\\AMDAPP\\bin\\x86_64;C: \\ProgramFiles(x86)\\AMDAPP\\bin\\x86;C: \\ProgramFiles(x86)\\Wizvera\\Delfino;C: \\ProgramFiles\\CommonFiles\\MicrosoftShared\\WindowsLive;C: \\ProgramFiles(x86)\\CommonFiles\\MicrosoftShared\\WindowsLive;C: \\ProgramFiles\\CollabNet\\SubversionClient;C: \\Windows\\system32;C: \\Windows;C: \\Windows\\System32\\Wbem;C: \\Windows\\System32\\WindowsPowerShell\\v1.0;C: \\Programs\\cygwin\\bin;C: \\Programs\\apache-maven-3.0.5\\bin;E: \\programs\\apache-ivy-2.3.0\\bin;E: \\programs\\apache-ant-1.9.0\\bin;C: \\ProgramFiles\\Java\\jdk1.7.0_17\\bin;C: \\ProgramFiles(x86)\\ATITechnologies\\ATI.ACE\\Core-Static;C: \\ProgramFiles(x86)\\QuickTime\\QTSystem;C: \\ProgramFiles\\SlikSvn\\bin;C: \\Programs\\emacs-24.2\\bin;C: \\ProgramFiles(x86)\\ESTsoft\\ALZip;C: \\Programs\\android-sdk-windows\\tools;C: \\Programs\\android-sdk-windows\\platform-tools;C: 

请参阅?在提供java.library.path的价值时停止。

我做错了吗?这是杰克逊的错吗?这是G / F的缓冲问题吗?

这是System.out为值打印的内容。

C:\Program Files\Java\jdk1.7.0_17\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Programs\cygwin\usr\local\bin;C:\Programs\cygwin\bin;C:\Program Files (x86)\PHP;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Program Files (x86)\Wizvera\Delfino;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files\CollabNet\Subversion Client;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Programs\cygwin\bin;C:\Programs\apache-maven-3.0.5\bin;E:\programs\apache-ivy-2.3.0\bin;E:\programs\apache-ant-1.9.0\bin;C:\Program Files\Java\jdk1.7.0_17\bin;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\QuickTime\QTSystem;C:\Program Files\SlikSvn\bin;C:\Programs\emacs-24.2\bin;C:\Program Files (x86)\ESTsoft\ALZip;C:\Programs\android-sdk-windows\tools;C:\Programs\android-sdk-windows\platform-tools;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Common Files\Autodesk Shared;C:\Program Files\Common Files\Autodesk Shared;C:\Program Files (x86)\Graphviz2.26.3\bin;C:\Programs\android-sdk-windows\tools;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn;C:\Program Files\Microsoft SQL Server\100\Tools\Binn;C:\Program Files\Microsoft SQL Server\100\DTS\Binn;C:\Programs\db-derby-10.8.2.2-bin\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\QuickTime\QTSystem;C:\Program Files\Microsoft Windows Performance Toolkit;C:\Program Files\Microsoft SDKs\Windows\v7.1\bin;C:\Program Files (x86)\Microsoft WSE\v3.0\Tools;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files (x86)\Graphviz 2.28\bin;C:\Program Files (x86)\ESTsoft\ALSee\x64;.

1 个答案:

答案 0 :(得分:0)

我解决了。我需要把它们放在上面。

generator.flush();
generator.close();