tags:

views:

62

answers:

1

hello, i am having an issue, where java is reading an array list from a YAML file of numbers, or strings, and it is interpreting the numbers as octal if it has a leading 0, and no 8-9 digit.

is there a way to force java to read the yaml field as a string?

code:

ArrayList recordrarray = (ArrayList) sect.get("recordnum");
   if (recordrarray != null) {
      recno = join (recordrarray, " ");
   }

HAVE ALSO TRIED:

Iterator<String> iter = recordrarray.iterator();
       if (iter.hasNext()) recno = " " +String.valueOf(iter.next());
       System.out.println(" this recnum:" + recno);
       while (iter.hasNext()){
          recno += ""+String.valueOf(iter.next()));

        System.out.println(" done recnum:" + String.valueOf(iter.next()));

       }

the input is such: 061456 changes to 25390 061506 changes to 25414 061559 -> FINE

it took a while to figure out what it was doing, and apparently this is a common issue for java,

ideas? thanks

edit: using jvyaml

yaml:

  22:
country_code: ' '
description: ''
insection: 1
recordnum:
  - 061264
type: misc

yaml loading:

import org.jvyaml.YAML;
Map structure = new HashMap();
structure = (Map) YAML.load(new FileReader(structurefn)); // load the structure file
A: 

Where are you reading the file? The problem lies in where the file contents are being read. Most likeley the recordarray list contains integers, ie. they have alreadey been parsed. Find the place where the records are being read. Maybe you are doing something like this:

int val = Integer.parseInt(record);

Use this instead:

int val = Integer.parseInt(record, 10);
Helgi
cant figure out how to format code in the comments.. :/
recursive9
It may be a big hash eventually, but something has to read the file and make that hash. Are you using a parsing library to read in the file? I'm guessing that's where your problem lies; perhaps one of your method calls has an incorrect parameter.
Chris
ok, the yaml file is a big hash, so to get this particular section out of it:` Map sect = (Map) sections.get(s);`then to get the array out of that section: ` ArrayList recordrarray = (ArrayList) sect.get("recordnum"); `those are the only places its being read.
recursive9
structure = (Map) YAML.load(new FileReader(structurefn)); // load the structure file is all that is happening
recursive9
@recursive9: can you attach the relevant portion of the YAML file? It may be the case that the YAML already contains the "wrong" numbers.
polygenelubricants
can you tell me how to paste code in the comments?
recursive9
' 22: country_code: ' ' description: '' insection: 1 recordnum: - 061264 type: misc'
recursive9
If you haven't already dug through the API, do that. If nothing comes of it, I would download the source and step through that method call (assuming the parser is open source, of course).
Chris
great, the documentation absolutely sucks for this class...
recursive9