I write an API using springMVC.It's a simple API, I just use it to test JsonProvider.
@ResponseBody
@RequestMapping(value = "/api/test", method = RequestMethod.GET)
public TestClass test(final HttpServletRequest request,
final HttpServletResponse response){
return new TestClass("cc");
}
class TestClass{
public TestClass(){
}
public TestClass(final String name) {
super();
this.name = name;
}
private String name;
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
}
The API simply returns
But JsonProvider
just throws a compile error.
Severity Code Description Project File Line
Error The type provider 'ProviderImplementation.JsonProvider' reported an error: Cannot read sample JSON from 'http://localhost/api/test': Invalid JSON starting at character 0, snippet =
----
"{\"name\":
-----
json =
------
"{\"name\":\"cc\"}"
------- JsonProcess c:\users\xx\documents\visual studio 2015\Projects\JsonProcess\JsonProcess\Program.fs 8
The F# code:
open FSharp.Data
[<Literal>]
let jsonValue = """
{"name":"cc"}
"""
type JsonData = JsonProvider<"http://localhost/api/test">
[<EntryPoint>]
let main argv =
0 // return an integer exit code
Use the String literal jsonValue
as sample is ok.type JsonData = JsonProvider<jsonValue>