Comments (4)
You can avoid the issue with
serde-hjson = { version = "0.9", default-features = false }
this will disable preservation of key order
I made a version that patches the issue (it was and still is UB but it seems to work for now).
https://github.com/Yarn/hjson-rust/tree/unitialized_fix
https://github.com/Yarn/linked-hash-map/tree/hjson_fix
you can use it with
serde-hjson = { git = "https://github.com/Yarn/hjson-rust.git", rev = "ae3a336153d0c4f757beb848d2059123be00cb75" }
My workaround for the older version of serde is to read the file to a serde_hjson::Value
then using an old version of serde_json to write json to a string then reading that string using a new version of serde_json
in Cargo.toml
serde-hjson = { git = "https://github.com/Yarn/hjson-rust.git", rev = "ae3a336153d0c4f757beb848d2059123be00cb75" }
serde_json = "1.0"
serde_json_old = { package = "serde_json", version = "0.8.6" }
in your code assuming Thing implements serde 1.0 deserialize
let mut f = std::fs::File::open(path).unwrap();
let a: serde_hjson::Value = serde_hjson::from_reader(f).unwrap();
let b = serde_json_old::to_string(&a).unwrap();
let thing: Thing = serde_json::from_str(&b).unwrap();
from hjson-rust.
sometimes the solution is in the obvious place
from hjson-rust.
what's the story with your nu_hjson fork, @jonathandturner ? I can't find the source and it looks like it is also on an older version of serde (0.8.23). From the issues list here there seems to be no viable hjson package for rust currently.
from hjson-rust.
@Nutomic has tried swapping out linked_hash_map
(the dead library causing this error) for hashlink
(a new, well maintained one). However unfortunately it has this error:
#[inline]
fn visit_map<'de, V>(&mut self, visitor: V) -> Result<Value, V::Error>
where V: de::MapVisitor,
// where V: de::MapAccess<'de>,
{
let values = try!(MapVisitor::default().visit_map(visitor));
Ok(Value::Object(values))
}
error:
error[E0599]: no method named `visit_map` found for struct `LinkedHashMapVisitor<_, _>` in the current scope
--> src/value.rs:442:57
|
442 | let values = try!(MapVisitor::default().visit_map(visitor));
| ^^^^^^^^^ method not found in `LinkedHashMapVisitor<_, _>`
|
= help: items from traits can only be used if the trait is in scope
= note: the following trait is implemented but not in scope; perhaps add a `use` for it:
`use serde::de::Visitor;`
This is because hashlink
requires serde::de::MapAccess
rather than serde::de::MapVisitor
, which unfortunately only newer versions of serde have.
I tried upgrading the serde version from 0.8.0
, but it causes ~100 errors that I'm not familiar enough with serde to fix.
edit: [here's the code: Nutomic/hjson-rust#use-hashlink
from hjson-rust.
Related Issues (17)
- Parse error on deserialization of enum value HOT 8
- Strips leading slashes from key names and string fields
- How to use Serialize/Deserialize derives with this crate? HOT 5
- from_str method failing with integer types.
- Depends on outdated linked-hash-map
- serde_hjson::from_slice panics on decoding invalid utf8
- Update to serde 0.9 HOT 1
- serde_hjson::from_slice panics on subtract with overflow
- serde_hjson::from_slice panics at 'removal index (is 0) should be < len (is 0)'
- serde_hjson::from_slice panics on ParseIntError
- Is this crate maintained? HOT 4
- Update to Serde 1.0 HOT 3
- Support for single quoted strings
- tests fail to compile due to quasi HOT 1
- Upgrade to Serde 1.0.x using Serde's JSON implementation HOT 19
- Numbers are always be parsed to Value::F64
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hjson-rust.