title: MOXy JAXB javax.xml.bind.PropertyException
body: <p>I followed this example: <a href="http://wiki.eclipse.org/EclipseLink/Examples/MOXy/JSON_Twitter" rel="nofollow noreferrer">http://wiki.eclipse.org/EclipseLink/Examples/MOXy/JSON_Twitter</a></p>
  
  <p>Now I have this class:</p>
  
  <pre><code>import javax.xml.bind.JAXBContext;
  import javax.xml.bind.JAXBElement;
  import javax.xml.bind.Marshaller;
  import javax.xml.bind.Unmarshaller;
  import javax.xml.transform.stream.StreamSource;
  
  import org.eclipse.persistence.jaxb.MarshallerProperties;
  
  public class Demo {
  
      public static void main(String[] args) throws Exception {
          JAXBContext jc = JAXBContext.newInstance(Foo.class);
  
          Unmarshaller unmarshaller = jc.createUnmarshaller();
          unmarshaller.setProperty("eclipselink.media-type", "application/json");
          unmarshaller.setProperty("eclipselink.json.include-root", false);
          StreamSource source = new StreamSource("http://test.url/path/to/resource");
          JAXBElement&lt;Foo&gt; jaxbElement = unmarshaller.unmarshal(source, Foo.class);
  
          System.out.println(jaxbElement.getValue().getFoo());
  
          Marshaller marshaller = jc.createMarshaller();
          marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
          marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
          marshaller.setProperty("eclipselink.json.include-root", false);
          marshaller.marshal(jaxbElement, System.out);
      }
  }
  </code></pre>
  
  <p>And I have <code>jaxb.properties</code>:</p>
  
  <pre><code>javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
  </code></pre>
  
  <p>If I run this code, I get:</p>
  
  <pre><code>Exception in thread "main" javax.xml.bind.PropertyException: name: eclipselink.media-type value: application/json
      at javax.xml.bind.helpers.AbstractUnmarshallerImpl.setProperty(AbstractUnmarshallerImpl.java:352)
      at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.setProperty(UnmarshallerImpl.java:450)
      at com.example.JavaSEClient.main(JavaSEClient.java:19)
  </code></pre>
  
  <p><strong>How can I fix this?</strong></p>
  
  <p>I searched SO and Google, these answers are not working:</p>
  
  <p><a href="https://stackoverflow.com/questions/18498635/propertyexception-when-setting-marshaller-property-with-eclipselink-media-type-v">PropertyException when setting Marshaller property with eclipselink.media-type value: application/json</a>
  <a href="https://stackoverflow.com/questions/7159675/jaxb-javax-xml-bind-propertyexception">JAXB javax.xml.bind.PropertyException</a></p>