Skip to content

Commit

Permalink
typo fix in docs and advocate for wrapper struct if custom serializat…
Browse files Browse the repository at this point in the history
…ion is used (#407)

* typo fix in docs

* add warning about already defined custom serialization

* add warning about already defined custom serialization

* add warning about already defined custom serialization
  • Loading branch information
koehlerson authored Aug 1, 2022
1 parent e746c89 commit 10ff8b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion docs/src/customserialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ Base.convert(::Type{ASerialization}, a::A) = ASerialization([a.x])
Base.convert(::Type{A}, a::ASerialization) = A(only(a.x))
```

!!! warning "Already defined custom serialization"
Take care, some Julia internal types already use a `CustomSerialization` and JLD2.jl cannot nest them.
In order to avoid unexpected behavior you should define a wrapper type,
such as in the example above `ASerialization` even if you could use a simple Julia built in type (as in this case `Vector{Int}`).

If you do not want to overload `Base.convert` then you can also define

```julia
Expand All @@ -47,4 +52,4 @@ arr = [B(rand()) for i=1:10]
```

In this example JLD2 converts the array of `B` structs to a plain `Vector{Float64}` prior to
storing to disk.
storing to disk.
2 changes: 1 addition & 1 deletion docs/src/hdf5compat.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ it is shown here as it serves as a good example for usage of that feature.
```
Usually one would also have to define a method for `wconvert`. However, in this
case JLD2 figures out that ne explicit conversion is needed to construct `nothing`.
case JLD2 figures out that no explicit conversion is needed to construct `nothing`.

0 comments on commit 10ff8b7

Please sign in to comment.