title: Setting Content Type Header with Play Framework Java
body: <p>I'm using Play Framework 2.2.1 with Java. I'm trying to test my Controllers, in doing so I need to set the Content-Type header to "application/json". I've tried this using 'withHeader("Content-Type", "application/json") as well as 'withJsonBody' on my FakeRequest. Whenever I use either of these methods, it seems I get a null pointer exception. Any ideas on if this is a problem with how I'm setting the header?</p>
  
  <pre><code>FakeRequest fr = new FakeRequest("PUT", "/create");
  fr.withHeader(CONTENT_TYPE, "application/json");
  
  //I have tried this in place of calling withHeader as above
  //JsonNode arg0 = Json.parse("{\"test\":1}");
  //fr.withJsonBody(arg0);
  
  
   try {
       Result result = Helpers.route(fr);
       assertThat(result).isNotNull();
       assertThat(status(result)).isEqualTo(CREATED);
   }catch(Throwable t) {
       t.printStackTrace();
   }
  </code></pre>
  
  <p>This is the stack trace I get:</p>
  
  <pre><code>java.lang.NullPointerException
      at play.test.Helpers.unwrapJavaResult(Helpers.java:61)
      at play.test.Helpers.header(Helpers.java:220)
      at play.test.Helpers.charset(Helpers.java:254)
      at play.test.Helpers.contentAsString(Helpers.java:289)
      at controllers.GroupControllerTest$10.run(GroupControllerTest.java:233)
      at play.test.Helpers.running(Helpers.java:376)
      at controllers.GroupControllerTest.callPutFacetForGroupAdminAsAdmin(GroupControllerTest.java:216)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      at org.junit.runners.Suite.runChild(Suite.java:127)
      at org.junit.runners.Suite.runChild(Suite.java:26)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:138)
      at com.novocode.junit.JUnitRunner.run(JUnitRunner.java:90)
      at sbt.RunnerWrapper$1.runRunner2(FrameworkWrapper.java:220)
      at sbt.RunnerWrapper$1.execute(FrameworkWrapper.java:233)
      at sbt.ForkMain$Run.runTest(ForkMain.java:239)
      at sbt.ForkMain$Run.runTestSafe(ForkMain.java:211)
      at sbt.ForkMain$Run.runTests(ForkMain.java:187)
      at sbt.ForkMain$Run.run(ForkMain.java:251)
      at sbt.ForkMain.main(ForkMain.java:97)
  </code></pre>