mirror of
https://github.com/apache/jclouds.git
synced 2025-02-07 02:29:25 +00:00
Use a class with a File member
Using gson on a File directly breaks Java strong encapsulation.
This commit is contained in:
parent
db69360b5f
commit
e7894e5a77
@ -23,7 +23,6 @@ import java.io.File;
|
|||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.json.Json;
|
import org.jclouds.json.Json;
|
||||||
import org.jclouds.json.config.GsonModule;
|
import org.jclouds.json.config.GsonModule;
|
||||||
import org.testng.annotations.Ignore;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
@ -48,15 +47,19 @@ public class BindToJsonPayloadTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fails with Failed making field 'java.io.File#path' accessible; either increase its visibility or write a custom TypeAdapter for its declaring type.
|
private static class MyFile {
|
||||||
// This is serializing a File which we don't actually care about. Just pick a different type instead?
|
private MyFile(File path) {
|
||||||
@Ignore
|
this.path = path;
|
||||||
|
}
|
||||||
|
private final File path;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSomethingNotAMap() throws SecurityException, NoSuchMethodException {
|
public void testSomethingNotAMap() throws SecurityException, NoSuchMethodException {
|
||||||
BindToJsonPayload binder = new BindToJsonPayload(json);
|
BindToJsonPayload binder = new BindToJsonPayload(json);
|
||||||
|
|
||||||
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build();
|
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build();
|
||||||
request = binder.bindToRequest(request, new File("foo"));
|
request = binder.bindToRequest(request, new MyFile(new File("foo")));
|
||||||
assertEquals(request.getPayload().getRawContent(), "{\"path\":\"foo\"}");
|
assertEquals(request.getPayload().getRawContent(), "{\"path\":\"foo\"}");
|
||||||
assertEquals(request.getPayload().getContentMetadata().getContentType(), "application/json");
|
assertEquals(request.getPayload().getContentMetadata().getContentType(), "application/json");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user