Skip to content

Commit f5b24f7

Browse files
committed
fixed serialize/deserialize mixups
1 parent 872f346 commit f5b24f7

28 files changed

+83
-79
lines changed

src/json_file_module.F90

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,30 @@ module json_file_module
7676

7777
procedure,public :: get_core => get_json_core_in_file
7878

79+
!>
80+
! Load JSON from a file.
7981
procedure,public :: load => json_file_load
8082

8183
!>
8284
! The same as `load`, but only here for backward compatibility
8385
procedure,public :: load_file => json_file_load
8486

85-
generic,public :: serialize => MAYBEWRAP(json_file_load_from_string)
87+
!>
88+
! Load JSON from a string.
89+
generic,public :: deserialize => MAYBEWRAP(json_file_load_from_string)
8690

8791
!>
88-
! The same as `serialize`, but only here for backward compatibility
92+
! The same as `deserialize`, but only here for backward compatibility
8993
generic,public :: load_from_string => MAYBEWRAP(json_file_load_from_string)
9094

95+
!>
96+
! Print the [[json_value]] structure to an allocatable string
97+
procedure,public :: serialize => json_file_print_to_string
98+
99+
!>
100+
! The same as `serialize`, but only here for backward compatibility
101+
procedure,public :: print_to_string => json_file_print_to_string
102+
91103
procedure,public :: destroy => json_file_destroy
92104
procedure,public :: nullify => json_file_nullify
93105
procedure,public :: move => json_file_move_pointer
@@ -100,14 +112,6 @@ module json_file_module
100112
procedure,public :: check_for_errors => json_file_check_for_errors
101113
procedure,public :: clear_exceptions => json_file_clear_exceptions
102114

103-
!>
104-
! Print the [[json_value]] structure to an allocatable string
105-
procedure,public :: deserialize => json_file_print_to_string
106-
107-
!>
108-
! The same as `deserialize`, but only here for backward compatibility
109-
procedure,public :: print_to_string => json_file_print_to_string
110-
111115
generic,public :: print => json_file_print_to_console, &
112116
json_file_print_to_unit, &
113117
json_file_print_to_filename
@@ -641,7 +645,7 @@ function initialize_json_file_from_string(str,&
641645
call file_object%initialize(&
642646
#include "json_initialize_dummy_arguments.inc"
643647
)
644-
call file_object%serialize(str)
648+
call file_object%deserialize(str)
645649

646650
end function initialize_json_file_from_string
647651
!*****************************************************************************************
@@ -685,7 +689,7 @@ function initialize_json_file_from_string_v2(str, json_core_object) &
685689
type(json_core),intent(in) :: json_core_object
686690

687691
file_object%core = json_core_object
688-
call file_object%serialize(str)
692+
call file_object%deserialize(str)
689693

690694
end function initialize_json_file_from_string_v2
691695
!*****************************************************************************************
@@ -857,7 +861,7 @@ end subroutine json_file_load
857861
! Load JSON from a string:
858862
!```fortran
859863
! type(json_file) :: f
860-
! call f%serialize('{ "name": "Leonidas" }')
864+
! call f%deserialize('{ "name": "Leonidas" }')
861865
!```
862866

863867
subroutine json_file_load_from_string(me, str)
@@ -867,7 +871,7 @@ subroutine json_file_load_from_string(me, str)
867871
class(json_file),intent(inout) :: me
868872
character(kind=CK,len=*),intent(in) :: str !! string to load JSON data from
869873

870-
call me%core%serialize(me%p, str)
874+
call me%core%deserialize(me%p, str)
871875

872876
end subroutine json_file_load_from_string
873877
!*****************************************************************************************
@@ -883,7 +887,7 @@ subroutine wrap_json_file_load_from_string(me, str)
883887
class(json_file),intent(inout) :: me
884888
character(kind=CDK,len=*),intent(in) :: str
885889

886-
call me%serialize(to_unicode(str))
890+
call me%deserialize(to_unicode(str))
887891

888892
end subroutine wrap_json_file_load_from_string
889893
!*****************************************************************************************
@@ -970,7 +974,7 @@ end subroutine json_file_print_to_filename
970974
! type(json_file) :: f
971975
! character(kind=CK,len=:),allocatable :: str
972976
! call f%load('my_file.json')
973-
! call f%deserialize(str)
977+
! call f%serialize(str)
974978
!```
975979

976980
subroutine json_file_print_to_string(me,str)
@@ -980,7 +984,7 @@ subroutine json_file_print_to_string(me,str)
980984
class(json_file),intent(inout) :: me
981985
character(kind=CK,len=:),allocatable,intent(out) :: str !! string to print JSON data to
982986

983-
call me%core%deserialize(me%p,str)
987+
call me%core%serialize(me%p,str)
984988

985989
end subroutine json_file_print_to_string
986990
!*****************************************************************************************

src/json_value_module.F90

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -562,14 +562,6 @@ module json_value_module
562562
procedure,private :: json_get_by_path_rfc6901
563563
procedure,private :: json_get_by_path_jsonpath_bracket
564564

565-
!>
566-
! Print the [[json_value]] structure to an allocatable string
567-
procedure,public :: deserialize => json_value_to_string
568-
569-
!>
570-
! The same as `deserialize`, but only here for backward compatibility
571-
procedure,public :: print_to_string => json_value_to_string
572-
573565
!>
574566
! Print the [[json_value]] to an output unit or file.
575567
!
@@ -764,13 +756,21 @@ module json_value_module
764756
generic,public :: load => json_parse_file
765757
procedure :: json_parse_file
766758

759+
!>
760+
! Print the [[json_value]] structure to an allocatable string
761+
procedure,public :: serialize => json_value_to_string
762+
763+
!>
764+
! The same as `serialize`, but only here for backward compatibility
765+
procedure,public :: print_to_string => json_value_to_string
766+
767767
!>
768768
! Parse the JSON string and populate the [[json_value]] tree.
769-
generic,public :: serialize => MAYBEWRAP(json_parse_string)
769+
generic,public :: deserialize => MAYBEWRAP(json_parse_string)
770770
procedure :: MAYBEWRAP(json_parse_string)
771771

772772
!>
773-
! Same as `load` and `serialize` but only here for backward compatibility.
773+
! Same as `load` and `deserialize` but only here for backward compatibility.
774774
generic,public :: parse => json_parse_file, &
775775
MAYBEWRAP(json_parse_string)
776776

@@ -9823,7 +9823,7 @@ subroutine wrap_json_parse_string(json, p, str)
98239823
type(json_value),pointer :: p !! output structure
98249824
character(kind=CDK,len=*),intent(in) :: str !! string with JSON data
98259825

9826-
call json%serialize(p,to_unicode(str))
9826+
call json%deserialize(p,to_unicode(str))
98279827

98289828
end subroutine wrap_json_parse_string
98299829
!*****************************************************************************************

src/tests/jf_test_06.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ subroutine test_6(error_cnt)
6262
if (files(i)=='') then
6363
write(error_unit,'(A)') 'load string: '//invalid_str
6464
write(error_unit,'(A)') ''
65-
call json%serialize(str = invalid_str)
65+
call json%deserialize(str = invalid_str)
6666
else
6767
write(error_unit,'(A)') 'load file: '//trim(files(i))
6868
write(error_unit,'(A)') ''

src/tests/jf_test_08.F90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ subroutine test_8(error_cnt)
5757
write(error_unit,'(A)') ' Valid test 1:'
5858
write(error_unit,'(A)') '**************'
5959
write(error_unit,'(A)') ''
60-
call json%load(str=str, p=p) ! read it from str
60+
call json%deserialize(str=str, p=p) ! read it from str
6161
if (json%failed()) then
6262
call json%print_error_message(error_unit)
6363
error_cnt = error_cnt + 1
@@ -80,7 +80,7 @@ subroutine test_8(error_cnt)
8080
write(error_unit,'(A)') ' Valid test 2:'
8181
write(error_unit,'(A)') '**************'
8282
write(error_unit,'(A)') ''
83-
call json%load(str=str2, p=p) ! read it from str
83+
call json%deserialize(str=str2, p=p) ! read it from str
8484
if (json%failed()) then
8585
call json%print_error_message(error_unit)
8686
error_cnt = error_cnt + 1
@@ -103,7 +103,7 @@ subroutine test_8(error_cnt)
103103
write(error_unit,'(A)') ' Invalid test:'
104104
write(error_unit,'(A)') '**************'
105105
write(error_unit,'(A)') ''
106-
call json%load(str=str_invalid, p=p) ! read it from str
106+
call json%deserialize(str=str_invalid, p=p) ! read it from str
107107
if (json%failed()) then
108108
call json%print_error_message(error_unit)
109109
else

src/tests/jf_test_09.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ subroutine test_9(error_cnt)
8080
write(error_unit,'(A)') '================================='
8181

8282
write(error_unit,'(A)') ''
83-
write(error_unit,'(A)') ' Load a file using json_file%serialize'
83+
write(error_unit,'(A)') ' Load a file using json_file%deserialize'
8484
write(error_unit,'(A)') ''
8585
write(error_unit,'(A)') 'Loading file: '//trim(filename)
8686

8787
call cpu_time(tstart)
8888
call read_file(dir//filename, str)
8989

9090
if (allocated(str)) then
91-
call f%serialize(str)
91+
call f%deserialize(str)
9292
call cpu_time(tend)
9393
write(error_unit,'(A,1X,F10.3,1X,A)') 'Elapsed time to parse: ',tend-tstart,' sec'
9494
if (f%failed()) then

src/tests/jf_test_10.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ subroutine test_10(error_cnt)
7474
end if
7575

7676
write(error_unit,'(A)') 'json_file_load_from_string...'
77-
call f%serialize(json_str)
77+
call f%deserialize(json_str)
7878
if (f%failed()) then
7979
call f%print_error_message(error_unit)
8080
error_cnt = error_cnt + 1
@@ -83,7 +83,7 @@ subroutine test_10(error_cnt)
8383
end if
8484

8585
write(error_unit,'(A)') 'json_file_print_to_string...'
86-
call f%deserialize(str)
86+
call f%serialize(str)
8787
if (f%failed()) then
8888
call f%print_error_message(error_unit)
8989
error_cnt = error_cnt + 1

src/tests/jf_test_11.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ subroutine test_11(error_cnt)
115115
end if
116116

117117
write(error_unit,'(A)') ''
118-
call json%deserialize(cval)
118+
call json%serialize(cval)
119119
if (json%failed()) then
120120
call json%print_error_message(error_unit)
121121
error_cnt = error_cnt + 1

src/tests/jf_test_13.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ subroutine test_13(error_cnt)
4343

4444
call my_file%initialize(real_format=trim(fmts(i)))
4545

46-
call my_file%serialize('{ "value": 1234.56789 }')
46+
call my_file%deserialize('{ "value": 1234.56789 }')
4747
if (my_file%failed()) then
4848
call my_file%print_error_message(error_unit)
4949
error_cnt = error_cnt + 1
5050
end if
51-
call my_file%deserialize(str)
51+
call my_file%serialize(str)
5252
if (my_file%failed()) then
5353
call my_file%print_error_message(error_unit)
5454
error_cnt = error_cnt + 1

src/tests/jf_test_15.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ subroutine test_15(error_cnt)
4545
nullify(p2)
4646
nullify(p)
4747

48-
call json%load(p2, '{"int": 1, "real": 2.0, "logical": true}')
48+
call json%deserialize(p2, '{"int": 1, "real": 2.0, "logical": true}')
4949
call json%get(p2,'real', i)
5050
call json%get(p2,'logical',i)
5151
call json%get(p2,'integer',d)

src/tests/jf_test_16.F90

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ subroutine test_16(error_cnt)
3838

3939
write(error_unit,'(A)') ''
4040
write(error_unit,'(A)') 'Original:'
41-
call json%load(p, '{"cities": ["New York","Los Angeles","Chicago"], '//&
41+
call json%deserialize(p, '{"cities": ["New York","Los Angeles","Chicago"], '//&
4242
'"value": 1, "iflag": true, "struct":{"vec":[1,2,3]}}')
4343
if (json%failed()) then
4444
call json%print_error_message(error_unit)
@@ -94,10 +94,10 @@ subroutine test_16(error_cnt)
9494
write(error_unit,'(A)') '.....................................'
9595
write(error_unit,'(A)') ''
9696
write(error_unit,'(A)') 'Original:'
97-
call json%load(p, '{ "stats": { "iflag": 0, "str": "ok" },'//&
98-
'"vars": [{ "label": "r", "value": 0.0 }, '//&
99-
'{ "label": "v", "value": 0.0 }],'//&
100-
'"empty": { } }')
97+
call json%deserialize(p, '{ "stats": { "iflag": 0, "str": "ok" },'//&
98+
'"vars": [{ "label": "r", "value": 0.0 }, '//&
99+
'{ "label": "v", "value": 0.0 }],'//&
100+
'"empty": { } }')
101101
if (json%failed()) then
102102
call json%print_error_message(error_unit)
103103
error_cnt = error_cnt + 1
@@ -144,7 +144,7 @@ subroutine test_16(error_cnt)
144144
write(error_unit,'(A)') '.....................................'
145145
write(error_unit,'(A)') ''
146146
write(error_unit,'(A)') 'Original:'
147-
call json%load(p, '{ "color": "red", "width": 10, "height": 2 }')
147+
call json%deserialize(p, '{ "color": "red", "width": 10, "height": 2 }')
148148
if (json%failed()) then
149149
call json%print_error_message(error_unit)
150150
error_cnt = error_cnt + 1
@@ -169,7 +169,7 @@ subroutine test_16(error_cnt)
169169
write(error_unit,'(A)') '.....................................'
170170
write(error_unit,'(A)') ''
171171
write(error_unit,'(A)') 'Original:'
172-
call json%load(p, '{ "color": "red", "width": 10, "height": 2 }')
172+
call json%deserialize(p, '{ "color": "red", "width": 10, "height": 2 }')
173173
if (json%failed()) then
174174
call json%print_error_message(error_unit)
175175
error_cnt = error_cnt + 1
@@ -194,7 +194,7 @@ subroutine test_16(error_cnt)
194194
write(error_unit,'(A)') '.....................................'
195195
write(error_unit,'(A)') ''
196196
write(error_unit,'(A)') 'Original:'
197-
call json%load(p, '{ "color": "red", "width": 10, "height": 2 }')
197+
call json%deserialize(p, '{ "color": "red", "width": 10, "height": 2 }')
198198
if (json%failed()) then
199199
call json%print_error_message(error_unit)
200200
error_cnt = error_cnt + 1

0 commit comments

Comments
 (0)