hashicorp / hashicorp/hcl

Unmarshal Custom Types

Open
#349 5 comments 11 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
5.8k
Forks
657
Avg merge
20h 36m
Merged PRs (30d)
6

Description

Is there a way to decode custom types? I'm looking for something equivalent to `encoding/json.Unmarshaler`. I've tried implementing `encoding.TextUnmarshaler` which didn't work.

Here's an example use-case.
``` go
type Duration struct {
time.Duration
}

func (d *Duration) UnmarshalText(data []byte) error {
d0, err := time.ParseDuration(string(data))
if err != nil {
return err
}
d.Duration = d0
return nil
}
```

SO Question: https://stackoverflow.com/questions/60515131/hcl-unmarshal-custom-types

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by inspecting the repository’s existing Go decoding behavior and how it handles encoding.TextUnmarshaler; the issue provides no file or test path. Define the supported custom-type contract using the Duration example, then add coverage demonstrating successful decoding and error handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.