Skip to content

Commit cb60228

Browse files
committed
added field that is not annotated with json tag
1 parent afed9fc commit cb60228

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

typescriptify/typescriptify.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,8 @@ func (t *TypeScriptify) getJSONFieldName(field reflect.StructField, isPtr bool)
535535
if !ignored && isPtr || hasOmitEmpty {
536536
jsonFieldName = fmt.Sprintf("%s?", jsonFieldName)
537537
}
538+
} else if field.IsExported() {
539+
jsonFieldName = field.Name
538540
}
539541
return jsonFieldName
540542
}

typescriptify/typescriptify_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,3 +968,25 @@ export class prefix_Example {
968968
`
969969
testConverter(t, converter, true, desiredResult, nil)
970970
}
971+
972+
func TestFieldNamesWithoutJSONAnnotation(t *testing.T) {
973+
t.Parallel()
974+
975+
type WithoutAnnotation struct {
976+
PublicField string
977+
privateField string
978+
}
979+
980+
converter := New().Add(WithoutAnnotation{})
981+
desiredResult := `
982+
export class WithoutAnnotation {
983+
PublicField: string;
984+
985+
constructor(source: any = {}) {
986+
if ('string' === typeof source) source = JSON.parse(source);
987+
this.PublicField = source["PublicField"];
988+
}
989+
}
990+
`
991+
testConverter(t, converter, true, desiredResult, nil)
992+
}

0 commit comments

Comments
 (0)