1

I need to retrieve data from MongoDB. I am using Spring framework and MongoRepository. My problem is that the data is written to the DB by a different application as 2-element double array. This is the document as seen in MongoDB:

{    
    "options" : {
       "ampWavelength" : 3000,
       "continuumWindows" : [ 
           {
               "0" : 1140,
               "1" : 1150
           }, 
           {
               "0" : 1275,
               "1" : 1280
           }, 
           {
               "0" : 1320,
               "1" : 1330
           }]
    }
}

The problem is I can't retrieve the array with fields named "0" or "1". Is there any trick to it? So far I have tried creating "continuumWindows" object with fields named "_0" and "_1" or making a "double[][] continuumWindows" variable but neither has worked for me - I either retrieve 0, null or get an error.

1
  • I have the same result when using "@JsonProperty("0")". I retrieve 0.0. Commented May 7, 2016 at 14:37

1 Answer 1

1

Use @Field annotation. Example:

public class ContinuumWindow {

    @Field(value = "0")
    private int elementZero;

    @Field(value = "1")
    private int elementOne;

}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I am just beginning to use Spring and forgot about this annotation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.