Rectangle 27 7

This is a paste from one of my methods (Restlet 2.0). Here I have a form that includes one file upload plus other fields, therefore it is rather complete:

@Post
public Representation createTransaction(Representation entity) {
    Representation rep = null;
    if (entity != null) {
        if (MediaType.MULTIPART_FORM_DATA.equals(entity.getMediaType(), true)) {
            // 1/ Create a factory for disk-based file items
            DiskFileItemFactory factory = new DiskFileItemFactory();
            factory.setSizeThreshold(1000240);

            // 2/ Create a new file upload handler
            RestletFileUpload upload = new RestletFileUpload(factory);
            List<FileItem> items;
            try {
                // 3/ Request is parsed by the handler which generates a list of FileItems
                items = upload.parseRequest(getRequest());

                Map<String, String> props = new HashMap<String, String>();
                File file = null;
                String filename = null;

                for (final Iterator<FileItem> it = items.iterator(); it.hasNext(); ) {
                    FileItem fi = it.next();
                    String name = fi.getName();
                    if (name == null) {
                        props.put(fi.getFieldName(), new String(fi.get(), "UTF-8"));
                    } else {
                        String tempDir = System.getProperty("java.io.tmpdir");
                        file = new File(tempDir + File.separator + "file.txt");
                        filename = name;
                        fi.getInputStream();
                        fi.write(file);
                    }
                }

                // [...] my processing code

                String redirectUrl = ...; // address of newly created resource
                getResponse().redirectSeeOther(redirectUrl);
            } catch (Exception e) {
                // The message of all thrown exception is sent back to
                // client as simple plain text
                getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                e.printStackTrace();
                rep = new StringRepresentation(e.getMessage(), MediaType.TEXT_PLAIN);
            }
        } else {
            // other format != multipart form data
            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            rep = new StringRepresentation("Multipart/form-data required", MediaType.TEXT_PLAIN);
        }
    } else {
        // POST request with no entity.
        getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
        rep = new StringRepresentation("Error", MediaType.TEXT_PLAIN);
    }

    return rep;
}

I'll end up refactoring it to something more generic, but this is what I have by now.

but don't you need an annotation for the Post request, like @Post("form") or something? I get a 405 returned for doing something very similar

I do have an @Post annotation (but with no parameters). The parameter limits the representations you accept (restlet.org/documentation/2.0/jse/api/org/restlet/resource/). The HTTP 405 is method not allowed (w3.org/Protocols/rfc2616/rfc2616-sec10.html) - Restlet may not recognise your resource as 'postable' if no @Post annotation is present.

I had it as just @Post, and it continued to return a 405. Then I added this: getMetadataService().addExtension("multipart", MediaType.MULTIPART_FORM_DATA, true); to the resources constructor, and changed my annotation from @Post to @Post("multipart") and it then worked.

java - RESTlet: How to process multipart/form-data requests? - Stack O...

java restlet multipartform-data
Rectangle 27 7

This is a paste from one of my methods (Restlet 2.0). Here I have a form that includes one file upload plus other fields, therefore it is rather complete:

@Post
public Representation createTransaction(Representation entity) {
    Representation rep = null;
    if (entity != null) {
        if (MediaType.MULTIPART_FORM_DATA.equals(entity.getMediaType(), true)) {
            // 1/ Create a factory for disk-based file items
            DiskFileItemFactory factory = new DiskFileItemFactory();
            factory.setSizeThreshold(1000240);

            // 2/ Create a new file upload handler
            RestletFileUpload upload = new RestletFileUpload(factory);
            List<FileItem> items;
            try {
                // 3/ Request is parsed by the handler which generates a list of FileItems
                items = upload.parseRequest(getRequest());

                Map<String, String> props = new HashMap<String, String>();
                File file = null;
                String filename = null;

                for (final Iterator<FileItem> it = items.iterator(); it.hasNext(); ) {
                    FileItem fi = it.next();
                    String name = fi.getName();
                    if (name == null) {
                        props.put(fi.getFieldName(), new String(fi.get(), "UTF-8"));
                    } else {
                        String tempDir = System.getProperty("java.io.tmpdir");
                        file = new File(tempDir + File.separator + "file.txt");
                        filename = name;
                        fi.getInputStream();
                        fi.write(file);
                    }
                }

                // [...] my processing code

                String redirectUrl = ...; // address of newly created resource
                getResponse().redirectSeeOther(redirectUrl);
            } catch (Exception e) {
                // The message of all thrown exception is sent back to
                // client as simple plain text
                getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                e.printStackTrace();
                rep = new StringRepresentation(e.getMessage(), MediaType.TEXT_PLAIN);
            }
        } else {
            // other format != multipart form data
            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            rep = new StringRepresentation("Multipart/form-data required", MediaType.TEXT_PLAIN);
        }
    } else {
        // POST request with no entity.
        getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
        rep = new StringRepresentation("Error", MediaType.TEXT_PLAIN);
    }

    return rep;
}

I'll end up refactoring it to something more generic, but this is what I have by now.

but don't you need an annotation for the Post request, like @Post("form") or something? I get a 405 returned for doing something very similar

I do have an @Post annotation (but with no parameters). The parameter limits the representations you accept (restlet.org/documentation/2.0/jse/api/org/restlet/resource/). The HTTP 405 is method not allowed (w3.org/Protocols/rfc2616/rfc2616-sec10.html) - Restlet may not recognise your resource as 'postable' if no @Post annotation is present.

I had it as just @Post, and it continued to return a 405. Then I added this: getMetadataService().addExtension("multipart", MediaType.MULTIPART_FORM_DATA, true); to the resources constructor, and changed my annotation from @Post to @Post("multipart") and it then worked.

java - RESTlet: How to process multipart/form-data requests? - Stack O...

java restlet multipartform-data
Rectangle 27 1

Then in your loop through your items, you can test whether they are or not fileItems with the method: isFormField().

Testing if a fileItem is a formField... makes sens ? ;) but it works.

java - RESTlet: How to process multipart/form-data requests? - Stack O...

java restlet multipartform-data
Rectangle 27 1

Then in your loop through your items, you can test whether they are or not fileItems with the method: isFormField().

Testing if a fileItem is a formField... makes sens ? ;) but it works.

java - RESTlet: How to process multipart/form-data requests? - Stack O...

java restlet multipartform-data
Rectangle 27 8

To send different SOAP requests to different SOAP services, you just need to make your WebServiceTemplate aware of all requests and responses it will have to process.

Create a Java class for each request and response like so:

package models;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;

@XmlRootElement
public class FlyRequest implements Serializable {

    private boolean nearByDeparture;

    public FlyRequest() {}

    public boolean isNearByDeparture() {
        return nearByDeparture;
    }

    public void setNearByDeparture(boolean nearByDeparture) {
        this.nearByDeparture = nearByDeparture;
    }
}

The setup of the template is done for example like so:

SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory(MessageFactory.newInstance());
    messageFactory.afterPropertiesSet();

    WebServiceTemplate webServiceTemplate = new WebServiceTemplate(messageFactory);
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setContextPath("models");
    marshaller.afterPropertiesSet();

    webServiceTemplate.setMarshaller(marshaller);
    webServiceTemplate.afterPropertiesSet();

"models" is the name of the package where the Request/Responses classes are, so that jaxb can find them.

Then you just instantiate the request of the class you want to perform the call, like so:

// call fly service:
    FlyRequest flyRequest = new FlyRequest();
    flyRequest.setNearByDeparture(false);
    Object flyResponse = webServiceTemplate.marshalSendAndReceive("https://example.net/fly", flyRequest);

    // call purchase service:
    PurchaseRequest purchaseRequest = new PurchaseRequest();
    purchaseRequest.setPrice(100);
    Object purchaseResponse = webServiceTemplate.marshalSendAndReceive("https://example.net/purchase", purchaseRequest);

Similarly, you can cast the response objects into your JAXB classes defined above.

I used the code but it returns following Caused by: javax.xml.bind.JAXBException: "my.project.flights.wegolo" doesnt contain ObjectFactory.class or jaxb.index

java - How to send a SOAP request using WebServiceTemplate? - Stack Ov...

java spring web-services soap jaxb
Rectangle 27 2

A process is a collection of virtual memory space, code, data, and system resources. A thread is code that is to be serially executed within a process. A processor executes threads, not processes, so each application has at least one process, and a process always has at least one thread of execution, known as the primary thread. A process can have multiple threads in addition to the primary thread. Prior to the introduction of multiple threads of execution, applications were all designed to run on a single thread of execution.

When a thread begins to execute, it continues until it is killed or until it is interrupted by a thread with higher priority (by a user action or the kernel's thread scheduler). Each thread can run separate sections of code, or multiple threads can execute the same section of code. Threads executing the same block of code maintain separate stacks. Each thread in a process shares that process's global variables and resources.

java - Difference between process and thread - Stack Overflow

java multithreading process
Rectangle 27 23

JavaScript is an object-oriented scripting language that allows you to create dynamic HTML pages, allowing you to process input data and maintain data, usually within the browser.

Java is a programming language, core set of libraries, and virtual machine platform that allows you to create compiled programs that run on nearly every platform, without distribution of source code in its raw form or recompilation.

While the two have similar names, they are really two completely different programming languages/models/platforms, and are used to solve completely different sets of problems.

Also, this is directly from the Wikipedia Javascript article:

A common misconception is that JavaScript is similar or closely related to Java; this is not so. Both have a C-like syntax, are object-oriented, are typically sandboxed and are widely used in client-side Web applications, but the similarities end there. Java has static typing; JavaScript's typing is dynamic (meaning a variable can hold an object of any type and cannot be restricted). Java is loaded from compiled bytecode; JavaScript is loaded as human-readable code. C is their last common ancestor language.

Javascript isn't just for HTML pages, Java6 now includes it, BIRT uses it for report scripting - I'm sure that there are other non-HTML uses beyond these two.

You're right. With the development of Rhino, and some of the other developments you mentioned, Javascript has come pretty far out of the browser sandbox.

Scripting is simply one particular kind of programming... instead you should say perhaps that Java is a compiled programming language and javascript is a scripting or interpreted programming language.

What's the difference between JavaScript and Java? - Stack Overflow

java javascript
Rectangle 27 23

JavaScript is an object-oriented scripting language that allows you to create dynamic HTML pages, allowing you to process input data and maintain data, usually within the browser.

Java is a programming language, core set of libraries, and virtual machine platform that allows you to create compiled programs that run on nearly every platform, without distribution of source code in its raw form or recompilation.

While the two have similar names, they are really two completely different programming languages/models/platforms, and are used to solve completely different sets of problems.

Also, this is directly from the Wikipedia Javascript article:

A common misconception is that JavaScript is similar or closely related to Java; this is not so. Both have a C-like syntax, are object-oriented, are typically sandboxed and are widely used in client-side Web applications, but the similarities end there. Java has static typing; JavaScript's typing is dynamic (meaning a variable can hold an object of any type and cannot be restricted). Java is loaded from compiled bytecode; JavaScript is loaded as human-readable code. C is their last common ancestor language.

Javascript isn't just for HTML pages, Java6 now includes it, BIRT uses it for report scripting - I'm sure that there are other non-HTML uses beyond these two.

You're right. With the development of Rhino, and some of the other developments you mentioned, Javascript has come pretty far out of the browser sandbox.

Scripting is simply one particular kind of programming... instead you should say perhaps that Java is a compiled programming language and javascript is a scripting or interpreted programming language.

What's the difference between JavaScript and Java? - Stack Overflow

java javascript
Rectangle 27 76

Regarding reified generics in Java

The compiler is responsible for understanding Generics at compile time. The compiler is also responsible for throwing away this "understanding" of generic classes, in a process we call type erasure. All happens at compile time.

Note: Contrary to beliefs of majority of Java developers, it is possible to keep compile-time type information and retrieve this information at runtime, despite in a very restricted way. In other words: Java does provide reified generics in a very restricted way.

Notice that, at compile-time, the compiler has full type information available but this information is intentionally dropped in general when the byte code is generated, in a process known as type erasure. This is done this way due to compatibility issues: The intention of language designers was providing full source code compatibility and full byte code compatibility between versions of the platform. If it were implemented differently, you would have to recompile your legacy applications when migrating to newer versions of the platform. The way it was done, all method signatures are preserved (source code compatibility) and you don't need to recompile anything (binary compatibility).

If you need to keep compile-time type information, you need to employ anonymous classes. The point is: in the very special case of anonymous classes, it is possible to retrieve full compile-time type information at runtime which, in other words means: reified generics. This means that the compiler does not throw away type information when anonymous classes are involved; this information is kept in the generated binary code and the runtime system allows you to retrieve this information.

I've written an article about this subject:

A note about the technique described in the article above is that the technique is obscure for majority of developers. Despite it works and works well, most developers feel confused or uncomfortable with the technique. If you have a shared code base or plan to release your code to the public, I do not recommend the above technique. On the other hand, if you are the sole user of your code, you can take advantage of the power this technique delivers to you.

The article above has links to sample code.

Actually, they didn't maintain both binary and source compatibility: oracle.com/technetwork/java/javase/compatibility-137462.html Where can I read more about their intention? Docs say that it uses type erasure, but doesn't say why.

@Richard Indeed, excellent article! You could add that local classes work too and that, in both cases (anonymous and local classes), information about the desired type argument is kept only in case of direct access new Box<String>() {}; not in case of indirect access void foo(T) {...new Box<T>() {};...} because the compiler does not keep type information for the enclosing method declaration.

@RichardGomes PLEASE update the link

Java generics - type erasure - when and what happens - Stack Overflow

java generics type-erasure
Rectangle 27 75

Regarding reified generics in Java

The compiler is responsible for understanding Generics at compile time. The compiler is also responsible for throwing away this "understanding" of generic classes, in a process we call type erasure. All happens at compile time.

Note: Contrary to beliefs of majority of Java developers, it is possible to keep compile-time type information and retrieve this information at runtime, despite in a very restricted way. In other words: Java does provide reified generics in a very restricted way.

Notice that, at compile-time, the compiler has full type information available but this information is intentionally dropped in general when the byte code is generated, in a process known as type erasure. This is done this way due to compatibility issues: The intention of language designers was providing full source code compatibility and full byte code compatibility between versions of the platform. If it were implemented differently, you would have to recompile your legacy applications when migrating to newer versions of the platform. The way it was done, all method signatures are preserved (source code compatibility) and you don't need to recompile anything (binary compatibility).

If you need to keep compile-time type information, you need to employ anonymous classes. The point is: in the very special case of anonymous classes, it is possible to retrieve full compile-time type information at runtime which, in other words means: reified generics. This means that the compiler does not throw away type information when anonymous classes are involved; this information is kept in the generated binary code and the runtime system allows you to retrieve this information.

I've written an article about this subject:

A note about the technique described in the article above is that the technique is obscure for majority of developers. Despite it works and works well, most developers feel confused or uncomfortable with the technique. If you have a shared code base or plan to release your code to the public, I do not recommend the above technique. On the other hand, if you are the sole user of your code, you can take advantage of the power this technique delivers to you.

The article above has links to sample code.

Actually, they didn't maintain both binary and source compatibility: oracle.com/technetwork/java/javase/compatibility-137462.html Where can I read more about their intention? Docs say that it uses type erasure, but doesn't say why.

@Richard Indeed, excellent article! You could add that local classes work too and that, in both cases (anonymous and local classes), information about the desired type argument is kept only in case of direct access new Box<String>() {}; not in case of indirect access void foo(T) {...new Box<T>() {};...} because the compiler does not keep type information for the enclosing method declaration.

@RichardGomes PLEASE update the link

Java generics - type erasure - when and what happens - Stack Overflow

java generics type-erasure
Rectangle 27 15

Most definitely not. All threads in Java share the same address space so it is possible for one thread to trash things owned by another thread. In the Erlang VM this just isn't possible as each process is isolated from all others. That's the whole point of them. Any time your want to have one process do something with data from another your code has to send a message to the other process. The only things shared between processes are large binary objects and these are immutable.

Isn't it actually true that Erlang processes also share address space at the low level (at the language level, "address space" is meaningless anyway)? It's the only way to implement cheap green threads. Isolation is achieved by making sure no pointer observable by a process can dereference to another process's memory block.

Java has no concept of an address space. Java threads have access to each others' objects and static fields.

@immibis It is more appropriate to say that Java has no notion of ownership of objects by threads. By implication, objects are shared between threads.

Erlang Process vs Java Thread - Stack Overflow

java erlang elixir
Rectangle 27 15

Most definitely not. All threads in Java share the same address space so it is possible for one thread to trash things owned by another thread. In the Erlang VM this just isn't possible as each process is isolated from all others. That's the whole point of them. Any time your want to have one process do something with data from another your code has to send a message to the other process. The only things shared between processes are large binary objects and these are immutable.

Isn't it actually true that Erlang processes also share address space at the low level (at the language level, "address space" is meaningless anyway)? It's the only way to implement cheap green threads. Isolation is achieved by making sure no pointer observable by a process can dereference to another process's memory block.

Java has no concept of an address space. Java threads have access to each others' objects and static fields.

@immibis It is more appropriate to say that Java has no notion of ownership of objects by threads. By implication, objects are shared between threads.

Erlang Process vs Java Thread - Stack Overflow

java erlang elixir
Rectangle 27 5

You may need to read from the process's standard output, or close the standard input, before it will proceed. For reading the output, the problem is that the buffer can get full, blocking the program; for closing the input, the problem is that some programs will try to read data from there if it's available, waiting to do so. One or both of these tricks is very likely to straighten things out for you.

Thanks man. I closed ALL the blasted streams and it seems to work now. Process p = Runtime.getRuntime().exec(cmd.toString()); p.getInputStream().close(); p.getOutputStream().close(); p.getErrorStream().close(); Just closing the input stream didn't work for some reason.

process - Can't launch external program from Java without closing java...

java process runtime launch external-process
Rectangle 27 86

This is another approach to parse the the process list from the command "ps -e":

try {
    String line;
    Process p = Runtime.getRuntime().exec("ps -e");
    BufferedReader input =
            new BufferedReader(new InputStreamReader(p.getInputStream()));
    while ((line = input.readLine()) != null) {
        System.out.println(line); //<-- Parse data here.
    }
    input.close();
} catch (Exception err) {
    err.printStackTrace();
}

If you are using Windows, then you should change the line: "Process p = Runtime.getRun..." etc... (3rd line), for one that looks like this:

Process p = Runtime.getRuntime().exec
    (System.getenv("windir") +"\\system32\\"+"tasklist.exe");

how to get the process start time and end time

On Windows, run tasklist.exe /fo csv /nh to get the list in CSV format, that's much easier to parse.

but it is not showing the jar name. My executable jar name is helloDemo.jar. but it is not showing anything for it

Why wouldn't it work if I add a | grep java ? i.e. ps -elf | grep java won't return a thing, but ps -elf would work as expected.

It should be noted that the "windows specific" bit at the bottom appears to be unnecessary. On Windows 10, (.exec (Runtime/getRuntime) "tasklist")) (in Clojure, using Java-interop) correctly returns the tasklist process, even without specifying a directory.

How to get a list of current open windows/process with Java? - Stack O...

java process
Rectangle 27 1

Synchronization is for threads only it wont work for processes in Java. There is no utility in them working across processes, since the processes do not share any state that would need to be synchronized. A variable in one process will not have the same data as a variable in the other process

yes, I understand your answer, the processes do not share any state,but I wonder if two processes will access the same shared memory? in this case, shall we consider Synchronization?

java - Difference between process and thread - Stack Overflow

java multithreading process
Rectangle 27 19

$scope.saveForm = function () {
      var formData = new FormData();
      var file = $scope.myFile;
      var json = $scope.myJson;
      formData.append("file", file);
      formData.append("ad",JSON.stringify(json));//important: convert to string JSON!
      var req = {
        url: '/upload',
        method: 'POST',
        headers: {'Content-Type': undefined},
        data: formData,
        transformRequest: function (data, headersGetterFunction) {
          return data;
        }
      };
@RequestMapping(value = "/upload", method = RequestMethod.POST)
    public @ResponseBody
    Advertisement storeAd(@RequestPart("ad") String adString, @RequestPart("file") MultipartFile file) throws IOException {

        Advertisement jsonAd = new ObjectMapper().readValue(adString, Advertisement.class);
//do whatever you want with your file and jsonAd

Helped me sort out my issue too.. Thanks a lot @user3207391

consumes = MediaType.MULTIPART_FORM_DATA_VALUE
@RequestMapping

java - How to process a multipart request consisting of a file and a J...

java json spring rest multipartform-data
Rectangle 27 19

$scope.saveForm = function () {
      var formData = new FormData();
      var file = $scope.myFile;
      var json = $scope.myJson;
      formData.append("file", file);
      formData.append("ad",JSON.stringify(json));//important: convert to string JSON!
      var req = {
        url: '/upload',
        method: 'POST',
        headers: {'Content-Type': undefined},
        data: formData,
        transformRequest: function (data, headersGetterFunction) {
          return data;
        }
      };
@RequestMapping(value = "/upload", method = RequestMethod.POST)
    public @ResponseBody
    Advertisement storeAd(@RequestPart("ad") String adString, @RequestPart("file") MultipartFile file) throws IOException {

        Advertisement jsonAd = new ObjectMapper().readValue(adString, Advertisement.class);
//do whatever you want with your file and jsonAd

Helped me sort out my issue too.. Thanks a lot @user3207391

consumes = MediaType.MULTIPART_FORM_DATA_VALUE
@RequestMapping

java - How to process a multipart request consisting of a file and a J...

java json spring rest multipartform-data
Rectangle 27 10

This guy calls out to bash to get the PID. I'm not sure if there is an java solution to the problem.

/**
 * Gets a string representing the pid of this program - Java VM
 */
public static String getPid() throws IOException,InterruptedException {

  Vector<String> commands=new Vector<String>();
  commands.add("/bin/bash");
  commands.add("-c");
  commands.add("echo $PPID");
  ProcessBuilder pb=new ProcessBuilder(commands);

  Process pr=pb.start();
  pr.waitFor();
  if (pr.exitValue()==0) {
    BufferedReader outReader=new BufferedReader(new InputStreamReader(pr.getInputStream()));
    return outReader.readLine().trim();
  } else {
    System.out.println("Error while getting PID");
    return "";
  }
}

I think this will give the pid of the JVM process... not the process spawned by Java which I believe is what the question is asking.

I think you need to read a bit closer. It spawns a process thats only job is to echo its own PID to its stdout which itself is piping to the stdin file descriptor associated with the JVM.

Vectors are old-hat, and is synchronized - no real need to use that type of collection - try using an ArrayList instead. Just saying.

Just saying what? This is not germane to the problem. The question is about accessing a PID not java best practices.

How do I find the process ID (pid) of a process started in java? - Sta...

java process pid
Rectangle 27 1

For #1, Shared memory is memory (potentially) used by more than one process. This is basically if you run the same binary file in multiple processes or different processes are using a shared library. The heap is where allocated memory is stored (when you use new in Java). Since Java has its VM, it is allocating a lot of memory on the process level that you don't see in your java code. I think that yes, the majority of that 135 MB is from the JVM code/data itself. However, there is also the memory taken up by the stack (when you make a function call and have local variables) as well.

For #2, different amount of RAM would not affect how much "memory" is used when we let memory equal RAM + swap space. However, different processors (especially if we're talking about 32-bit vs. 64-bit) may use different amount of memory. Also, the way a process is compiled may change the amount of memory used because you can instruct a compiler to optimize for memory footprint over speed, as well as disabling some or all optimization altogether.

java - Measuring memory usage of a process on Linux - Stack Overflow

java linux memory-management valgrind
Rectangle 27 27

Here is a rough but more declarative solution. I haven't been able to get it down to a single annotation, but this seems to work well. Also not sure about performance on large data sets.

{
    "list": [
        {
            "wrapper": {
                "name": "Jack"
            }
        },
        {
            "wrapper": {
                "name": "Jane"
            }
        }
    ]
}
public class RootObject {
    @JsonProperty("list")
    @JsonDeserialize(contentUsing = SkipWrapperObjectDeserializer.class)
    @SkipWrapperObject("wrapper")
    public InnerObject[] innerObjects;
}
public class InnerObject {
    @JsonProperty("name")
    public String name;
}

Where the Jackson voodoo is implemented like:

@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotation
public @interface SkipWrapperObject {
    String value();
}

and

public class SkipWrapperObjectDeserializer extends JsonDeserializer<Object> implements
        ContextualDeserializer {
    private Class<?> wrappedType;
    private String wrapperKey;

    public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
            BeanProperty property) throws JsonMappingException {
        SkipWrapperObject skipWrapperObject = property
                .getAnnotation(SkipWrapperObject.class);
        wrapperKey = skipWrapperObject.value();
        JavaType collectionType = property.getType();
        JavaType collectedType = collectionType.containedType(0);
        wrappedType = collectedType.getRawClass();
        return this;
    }

    @Override
    public Object deserialize(JsonParser parser, DeserializationContext ctxt)
            throws IOException, JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        ObjectNode objectNode = mapper.readTree(parser);
        JsonNode wrapped = objectNode.get(wrapperKey);
        Object mapped = mapIntoObject(wrapped);
        return mapped;
    }

    private Object mapIntoObject(JsonNode node) throws IOException,
            JsonProcessingException {
        JsonParser parser = node.traverse();
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(parser, wrappedType);
    }
}
mapIntoObject(JsonNode)
readValue
JsonNode
traverse()
ObjectMapper.convertValue()
mapIntoObject
return mapper.convertValue(node, wrappedType);

java - Jackson - How to process (deserialize) nested JSON? - Stack Ove...

java json serialization jackson