Skip to content

Commit b342af9

Browse files
authored
fix .NET deserialization (#19)
- removes the `verse` property if it is undefined.
1 parent 209054a commit b342af9

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/verse-ref.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,27 @@ describe('VerseRef', () => {
187187
describe('Serialization', () => {
188188
it('should serialize empty VerseRef', () => {
189189
const vref = new VerseRef();
190-
expect(vref.toJSON()).toEqual({ book: '', chapterNum: 0, verseNum: 0 });
190+
191+
const json = vref.toJSON();
192+
193+
expect(json).toEqual({ book: '', chapterNum: 0, verseNum: 0 });
194+
// Needed to help .NET deserialization.
195+
expect(json).not.toHaveProperty('verse');
191196
});
192197

193198
it('should serialize VerseRef', () => {
194199
const vref = new VerseRef(1, 2, 3, ScrVers.Septuagint);
195-
expect(vref.toJSON()).toEqual({
200+
201+
const json = vref.toJSON();
202+
203+
expect(json).toEqual({
196204
book: 'GEN',
197205
chapterNum: 2,
198206
verseNum: 3,
199207
versificationStr: 'Septuagint',
200208
});
209+
// Needed to help .NET deserialization.
210+
expect(json).not.toHaveProperty('verse');
201211
});
202212

203213
it('should stringify VerseRef', () => {

src/verse-ref.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,15 @@ export class VerseRef {
484484
toJSON(): SerializedVerseRef {
485485
let verse: string | undefined = this.verse;
486486
if (verse === '' || verse === this.verseNum.toString()) verse = undefined;
487-
return {
487+
const json = {
488488
book: this.book,
489489
chapterNum: this.chapterNum,
490490
verseNum: this.verseNum,
491491
verse,
492492
versificationStr: this.versificationStr,
493493
};
494+
if (!verse) delete json.verse;
495+
return json;
494496
}
495497

496498
/**

0 commit comments

Comments
 (0)