Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problema with record ID #23

Open
svrolanski opened this issue Jun 5, 2019 · 4 comments
Open

Problema with record ID #23

svrolanski opened this issue Jun 5, 2019 · 4 comments

Comments

@svrolanski
Copy link

svrolanski commented Jun 5, 2019

If I have a fixed length records like this

Xmessage
XDother message
XDanother message

Where X, XD and XR are the Ids, BeanIO cannot identify the record type correctly.

@nicoschl
Copy link
Collaborator

nicoschl commented Jun 5, 2019

@svrolanski

Please provide your mapping.xml file or the equivalent code with the annotations

@svrolanski
Copy link
Author

class RecordX {
	public static final String ID_REG = "X";
	@Field(at = 0, length = 1, rid = true, literal = ID_REG)
	private String idReg;

class RecordXD {
	public static final String ID_REG = "XD";
	@Field(at = 0, length = 2, rid = true, literal = ID_REG)
	private String idReg;

class RecordXR {
	public static final String ID_REG = "XR";
	@Field(at = 0, length = 2, rid = true, literal = ID_REG)
	private String idReg;

@nicoschl
Copy link
Collaborator

nicoschl commented Jun 6, 2019

Your classes doesn't specify any min/max occurrences. How are your data then structured?
Is there only a single RecordX message and then any number of RecordXD and RecordXR records?

How do you define your StreamBuilder?

The above work for me with a simple change to RecordX:

@Record(minOccurs = 1, maxOccurs = 1)
public class RecordX {

Is the test data correct? Should the last message not start with XR? More example data could also be useful if the above does not answer/solve your problem.

@svrolanski
Copy link
Author

svrolanski commented Jun 6, 2019

There are any number (0..unbonded) of X/XD/XR records in any order. I just "new StreamBuilder()" and call addRecord(RecordX.class), ... for each class. The order I call addRecord() does not seem to matter also. I workaround the problem by creating two streamBuilder and then creating two unmarshallesr. I can check for the record type myself and use the correct unmarshaller:

public <T extends Record> T toRecord(String line) {
	if (line.startsWith(RecordXD.ID_REG) || line.startsWith(RecordXR.ID_REG))
		// has only RecordXD RecordXR
		return (T) unmarshallerXdXr.unmarshal(line);

	// has only RecordX
	return (T) unmarshaller.unmarshal(line);
}

Anyway, this definitely looks like a bug to me. Since sometimes you cannot control how the input file is created, you need to predict such situations where IDs might start with the same string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants